Null → Empty Character Conversion of Map in JsonNode

Asked 1 years ago, Updated 1 years ago, 72 views

Thank you for your help.
This is a server-side development in Java.

I'm binding data using Jackson's JsonNode mechanism, but what should I do if I want to convert it to an empty string when the value of the map in JsonNode has Null?
I can find samples to add Key/Value to the map and delete Key/Value from the map, but I am troubled that I cannot find the details of the above process.

java json jackson

2022-09-30 14:41

1 Answers

Judging from the content of the comments, I think the following implementation will work.

// First: need a custom serializer provider
DefaultSerializerProvider.Implsp=new DefaultSerializerProvider.Impl();
sp.setNullValueSerializer (newNullValueSerializer());
// And then configure mapper to use it
ObjectMapper m = new ObjectMapper();
m.setSerializerProvider(sp);


2022-09-30 14:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.