0

I want all null properties to be ignored during serialization, as such, I have used the setSkipNull(true) in the GensonBuilder.

Genson genson = new GensonBuilder().setSkipNull(true).create();

However, this seems to work only for properties that are not Collections. When serializing a property of the type Collection, instead of excluding it, Genson includes it with a value of [] (empty array).

How to exclude properties of type Collection that are null?

João Fé
  • 331
  • 2
  • 8
  • https://stackoverflow.com/a/23078637/2148953 – aran Feb 03 '21 at 17:23
  • 1
    I would like to use Genson library, not Gson. Thanks anyway. – João Fé Feb 03 '21 at 17:35
  • Just tried with version 1.6 and it works fine, null collections seem to be properly skipped instead of writing an empty array. If the collection is empty (but not null) it does just write and empty array. – eugen Feb 04 '21 at 18:43

0 Answers0