jsonschema2pojo: JSONB1 style output missing @JsonbCreator for enum
Hi,
we currently face a problem in our project where we try to switch from Jackson2 annotation style to JSONB1 if it comes to handle enum types.
Given the below json schema, the Jackson2 output creates a @JsonCreator annotation, whereas the JSONB1 output does not have that even though the equivalent @JsonbCreator annotation exists since JSON Binding 1.0.
JSON-Schema (can be tested online)
{
"type" : "object",
"properties" : {
"myEnum" : {
"type" : "string",
"enum" : ["one", "two", "three"]
}
}
}
Produces Jackson2 output like this
@JsonCreator
public static Example.MyEnum fromValue(String value) {
Example.MyEnum constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
}
But produces JSONB1 output like this (note the missing @JsonbCreator annotation
public static Example.MyEnum fromValue(String value) {
Example.MyEnum constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
}
When trying to map the json input string into a Java POJO, we get the following runtime exception:
Caused by: javax.json.bind.JsonbException: Internal error: No enum constant com.example.ClassName.EnumName.Constant
at org.eclipse.yasson.internal.Unmarshaller.deserializeItem(Unmarshaller.java:68)
at org.eclipse.yasson.internal.Unmarshaller.deserialize(Unmarshaller.java:51)
at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:59)
at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:66)
... 34 more
Caused by: java.lang.IllegalArgumentException: No enum constant com.example.ClassName.EnumName.Constant
at java.lang.Enum.valueOf(Enum.java:238)
at org.eclipse.yasson.internal.serializer.EnumTypeDeserializer.deserialize(EnumTypeDeserializer.java:37)
at org.eclipse.yasson.internal.serializer.EnumTypeDeserializer.deserialize(EnumTypeDeserializer.java:23)
Any idea why the @JsonbCreator annotation is missing in the generated JSONB1 class ?
This is currently a blocker for our JSONB1 migration of our code.
Any help appreciated.
Thx
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (4 by maintainers)
But we don’t need a solution for Jackson, right? The current approach using
JsonCreatorandJsonValueannotations works correctly.