jsonb-api
jsonb-api copied to clipboard
Clarify what happens if an unknown Enum value gets deserialised
Assume you have a Java class which has an Enum. What happens if a JSON input contains a value for that Enum which is not a valid Enum value?
The only useful sentence I could find in the spec is
Deserialization of a JSON value into an enum instance MUST be done
by calling the enum’s valueOf(String) method.
And valueOf(String) throws an IllegalArgumentException. Is this what is intended? Means should we blow up in that case with a JsonbException?
The other option would be to set the field to null.
JsonbException must be thrown in this case.
Great, thanks @m0mus. Now the question remains whether you think we should further clarify this in the spec?
We cannot change a spec document, but feel free to make changes in javadocs.
Closing this as stale
@aguibert I think it's too early to close. It makes sense updating the spec and clarify this behavior as Mark is suggesting.
IMO the spec is pretty clear already:
Deserialization of a JSON value into an enum instance MUST be done
by calling the enum’s valueOf(String) method.
If we pass an unknown enum value to enum's valueOf(String) method, then we do whatever valueOf(String) would do if an unknown value gets passed to it. No need to re-specify this in JSON-B.
I suppose we could append the text:
If deserializing the enum fails, an error is raised.
@m0mus do you have an estimate of where the spec asciidoc is? It looks like we just have skeleton information right now