Skip to content

jsonstream.serialize how to skip null fields #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gsigmund opened this issue Jun 22, 2019 · 3 comments
Open

jsonstream.serialize how to skip null fields #245

gsigmund opened this issue Jun 22, 2019 · 3 comments

Comments

@gsigmund
Copy link

gsigmund commented Jun 22, 2019

Hi,

Is there a way to extend the serializer so that it will skip fields that are null?

I need this to save space.

thx Gerald

@mailsanchu
Copy link

Hi Gerald, Did you find an answer? Thanks Sanchu

@drewgatchell
Copy link

@mailsanchu @gsigmund

Hi; I actually ended up figuring this out tonight.. you can actually use Gson Compatibility Mode to do this since GSON omits nulls by default. Probably not ideal (I'm not sure of the exact performance implications); but it's better than nothing at this stage.

POJO pojo = JsonIterator.deserialize(json_str, POJO.class);
GsonCompatibilityMode config = new GsonCompatibilityMode.Builder().build();
System.out.println(JsonStream.serialize(config, pojo));

@gmokki
Copy link

gmokki commented Nov 19, 2020

Adding @JsonProperty(defaultValueToOmit = "null") seems to do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants