FasterXML / jackson-docs

Documentation for the Jackson JSON processor.
719 stars 111 forks source link

Upgrade to 2.12.4, default deserialization to 1970-1-1 if the date is null #23

Closed 360631935 closed 1 month ago

360631935 commented 1 year ago

Spring Boot was upgraded to 2.5.4, Jackson 2.12.4, and the default value of 1970-1-1 was deserialized when no value was passed in the date field in the XML message. I didn't find a way to configure the solution. I had to choose to downgrade the Jackson version and currently use 2.9.10 to fix the 1970 default date.

cowtowncoder commented 1 year ago

This is not the right place to report such issues; but if you can create a stand-alone unit test (no Spring Boot dependencies, need to isolate), it'd make sense to report at:

https://github.com/FasterXML/jackson-dataformat-xml/issues

but definitely need more detail on exactly what XML, target POJO, XmlMapper configuration etc.

danibs commented 1 month ago

I found the solution 🥳

You must set the behaviour of coercionConfigFor:

XmlMapper mapper = new XmlMapper();
mapper.coercionConfigFor( LogicalType.DateTime ).setCoercion( CoercionInputShape.EmptyString, CoercionAction.AsNull );
360631935 commented 1 month ago

I found the solution 🥳

You must set the behaviour of coercionConfigFor:

XmlMapper mapper = new XmlMapper();
mapper.coercionConfigFor( LogicalType.DateTime ).setCoercion( CoercionInputShape.EmptyString, CoercionAction.AsNull );

Thank you. My solution is the same as yours