There is a record class in which one of the properties is an enum field.
The results of deserialization differ from what I'm looking for. Obviously, when the field is null or absent Jackson does not use the @JsonCreator method and just inserts null.
I would like to avoid that "special treatment" and deserialize nulls (and field absence as well) the same way as other values.
Model classes
record MyRec( String first, Color second ){} // --- enum Color{ RED, GREEN; @JsonCreator static Color fromName(String name){ if (name == null || "red".equals(name)){ return RED; } else if ("green".equals(name)) { return GREEN; } else { throw new IllegalArgumentException(name); } } } Results of deserialization
JSON actual intent ------------------------------------|-------------------|------------------|------ '{"first": "hi", "second": "red"}' MyRec("hi", RED) MyRec("hi", RED) | ok '{"first": "hi", "second": null}' MyRec("hi", null) MyRec("hi", RED) | ? '{"first": "hi"}' MyRec("hi", null) MyRec("hi", RED) | ? How to force Jackson to use the @JsonCreator method for deserializing nulls and absent values?