FasterXML / jackson-dataformat-xml

Extension for Jackson JSON processor that adds support for serializing POJOs as XML (and deserializing from XML) as an alternative to JSON
Apache License 2.0
574 stars 222 forks source link

Without setting `@JsonCreator` for the POJO, the `required` attribute in `@JsonProperty` is not checked #625

Closed linghengqian closed 10 months ago

linghengqian commented 10 months ago

We appreciate issues as very valuable contributions, but just to make sure here are things that are important to do before filing an issue:

TL;

[ERROR] com.lingh.RequiredTest.assertRequiredValue -- Time elapsed: 0.276 s <<< FAILURE!
org.opentest4j.AssertionFailedError: Expected com.fasterxml.jackson.databind.exc.MismatchedInputException to be thrown, but nothing was thrown.
        at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
        at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:73)
        at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:35)
        at org.junit.jupiter.api.Assertions.assertThrows(Assertions.java:3115)
        at com.lingh.RequiredTest.assertRequiredValue(RequiredTest.java:21)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
cowtowncoder commented 10 months ago

Correct: @JsonProperty(required=true) is only enforced if and when properties are passed via Creator method (constructor or static factory method). It would be nice to support if for Setter/Field injected properties too; it is one of "most-wanted" issues:

https://github.com/FasterXML/jackson-databind/issues/230

Closing this as duplicate (also note: this is not XML-specific issue but same for all backends).