-
-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken feature: EnumMap
lookup
#1083
Comments
Caused by original implementation: #237 Also affects Workaround: handlebars.registerHelpers(new HelperSource());
public static class HelperSource {
/**
* Workaround for `myEnumMap.[Foo]` and `lookup myEnumMap Foo` not working.
* Usage: Replace {@code (lookup someEnumMap someEnumKey)} with {@code (lookupEnumMap someEnumMap someEnumKey)}.
* @see https:/jknack/handlebars.java/issues/1083
*/
public static <E extends Enum<E>> Object lookupEnumMap(EnumMap<E, ?> map, E key) {
return map.get(key);
}
} |
TWiStErRob
changed the title
Broken feature:
Broken feature: Nov 25, 2023
EnumMap
lookup via myEnumMap.[Foo]
syntaxEnumMap
lookup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a model property
Map<Line, StatusChange> statuses = new EnumMap(Line.class);
where these are the enum definitions:
and this template:
{{statuses.[lineStatus.line].cssClass}}
, which now I understand is wrong, I think I needlookup
.However I did not get that understanding from the error message, since it was:
I had a look at the sources:
handlebars.java/handlebars/src/main/java/com/github/jknack/handlebars/context/MapValueResolver.java
Line 52 in 683c5e8
and debugged, where I confirmed that the code is passing in the wrong class:
then the error becomes a more meaningful:
Sadly this not only affects the error cases, the feature to be able to index into an
EnumMap
via aString
in[]
is broken too, because it won't find thevalueOf
given the wrong class. I tried{{statuses.[Bakerloo].cssClass}}
and got the sameis not an enum class
exception, even though according to theMapValueResolver
it should've "just worked".The text was updated successfully, but these errors were encountered: