I'm attempting to use a Jackson flag on the objectMapper
objectMapper.enable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES);
This should cause object deserialization to fail if a constructor argument is not set in the json. i.e. If a field is missing as opposed to being set to null.
But I noticed that it only works if the object I want to deserialize has a constructor like so
public MyObject(@JsonProperty("id") UUID id, @JsonProperty("url") URL url) {
this.id = id;
this.url = url;
}
That's a little problematic as I'd hoped to use lombok's @AllArgsConstructor to generate the constructor. But if the constructor is missing the @JsonProperty(..) the FAIL_ON_MISSING_CREATOR_PROPERTIES check does not work. Instead the parameters are passed in as null.
I've come across some solutions here Can't make Jackson and Lombok work together. But so far they're not working for me.
Any suggestions?
--- Update ---
The annotations on my class are
@Data
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class MyClass { ... }