diff --git a/src/main/java/com/hubspot/jinjava/el/TypeConvertingMapELResolver.java b/src/main/java/com/hubspot/jinjava/el/TypeConvertingMapELResolver.java index 73de933cc..7d90543e3 100644 --- a/src/main/java/com/hubspot/jinjava/el/TypeConvertingMapELResolver.java +++ b/src/main/java/com/hubspot/jinjava/el/TypeConvertingMapELResolver.java @@ -2,6 +2,7 @@ import java.util.Map; import javax.el.ELContext; +import javax.el.ELException; import javax.el.MapELResolver; public class TypeConvertingMapELResolver extends MapELResolver { @@ -21,9 +22,13 @@ public Object getValue(ELContext context, Object base, Object property) { if (base instanceof Map && !((Map) base).isEmpty()) { Class keyClass = ((Map) base).keySet().iterator().next().getClass(); - value = ((Map) base).get(TYPE_CONVERTER.convert(property, keyClass)); - if (value != null) { - context.setPropertyResolved(true); + try { + value = ((Map) base).get(TYPE_CONVERTER.convert(property, keyClass)); + if (value != null) { + context.setPropertyResolved(true); + } + } catch (ELException ex) { + value = null; } } diff --git a/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java b/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java index d096eb342..7e60db6b5 100644 --- a/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ext/AstDictTest.java @@ -7,6 +7,7 @@ import com.hubspot.jinjava.interpret.JinjavaInterpreter; import com.hubspot.jinjava.interpret.TemplateError.ErrorType; import java.util.Map; +import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -36,6 +37,13 @@ public void itGetsDictValuesWithEnumKeysUsingToString() { assertThat(interpreter.resolveELExpression("foo.barName", -1)).isEqualTo("test"); } + @Test + public void itDoesItemsMethodCall() { + interpreter.getContext().put("foo", ImmutableMap.of(TestEnum.BAR, "test")); + assertThat(interpreter.resolveELExpression("foo.items()", -1)) + .isInstanceOf(Set.class); + } + @Test public void itHandlesEmptyMaps() { interpreter.getContext().put("foo", ImmutableMap.of());