micronaut-projects / micronaut-serialization

Build Time Serialization APIs for Micronaut
Apache License 2.0
26 stars 18 forks source link

Change the default value for micronaut.serde.serialization.inclusion to non_null #560

Open runenielsen opened 1 year ago

runenielsen commented 1 year ago

Feature description

The default for micronaut.serde.serialization.inclusion is non_empty. It should be changed to non_null.

Reason: It is not correct to just remove empty strings and empty arrays from the resulting JSON when serializing. This may work fine in most cases for JavaScript, but it means that serialize + deserialize on some objects in more strict language like Java and Kotlin will result in objects, that are not a copy of the original.

non_null is a much more sensible default, that avoids this problem.

See also the failing test case testMicronautSerializationAndDeserializationWithEmptyProperties in SerializeEmptyPropertiesTest in https://github.com/runenielsen/serialize-empty-properties for a demonstration of a case where serialization + deserialization does not result in a copy of the original object.

All the failing test cases are fixed, when you add micronaut.serde.serialization.inclusion=non_null to application.properties.

Thanks for a great framework! 🙂

graemerocher commented 1 year ago

would be a breaking change and if done can't be done until Micronaut 5

graemerocher commented 1 year ago

FWIW all configuration possibilities are described at https://micronaut-projects.github.io/micronaut-serialization/latest/guide/configurationreference.html

runenielsen commented 1 year ago

Ah, thanks. I'm blind and didn't notice that link, because it is in the page header. Sorry about that.

I removed the part about the configuration documentation missing from the issue description 🙂