Created
March 18, 2016 12:58
-
-
Save craigotis/6f3cfaf29ecde4b0c63a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map; | |
import org.springframework.expression.ExpressionParser; | |
import org.springframework.expression.spel.SpelParseException; | |
import org.springframework.expression.spel.standard.SpelExpressionParser; | |
public class AposTest { | |
public static void main(String[] args) { | |
// Parse of {NormalValue:'INGREDIENT', 'Apostro''Value':'INGREDIENT'} failed with: EL1043E:(pos 12): Unexpected token. Expected 'rcurly(})' but was 'colon(:)' | |
tryParse("{NormalValue:'INGREDIENT', 'Apostro''Value':'INGREDIENT'}", "'Apostro''Value'"); | |
// Parse of {NormalValue:'INGREDIENT', ApostroValue:'INGREDIENT'} failed with: EL1043E:(pos 12): Unexpected token. Expected 'rcurly(})' but was 'colon(:)' | |
tryParse("{NormalValue:'INGREDIENT', ApostroValue:'INGREDIENT'}", "ApostroValue"); | |
// Parse of {'NormalValue':'INGREDIENT', 'ApostroValue':'INGREDIENT'} failed with: EL1043E:(pos 14): Unexpected token. Expected 'rcurly(})' but was 'colon(:)' | |
tryParse("{'NormalValue':'INGREDIENT', 'ApostroValue':'INGREDIENT'}", "ApostroValue"); | |
} | |
private static void tryParse(String mapString, String lookupString) { | |
try { | |
ExpressionParser parser = new SpelExpressionParser(); | |
Map<String, String> itemTypes = (Map) parser.parseExpression(mapString).getValue(); | |
for (Map.Entry<String, String> e : itemTypes.entrySet()) { | |
System.out.println(e.getKey() + ": " + e.getValue()); | |
} | |
System.out.println( | |
"Parse of " + mapString + "succeeded, map lookup of " + lookupString + " resulted in: " | |
+ parser.parseExpression(mapString + "[" + lookupString + "]").getValue()); | |
} catch (SpelParseException ex) { | |
System.out.println("Parse of " + mapString + " failed with: " + ex.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment