Skip to content
Advertisement

Serialize and Deserialize Java object having vavr list

I have a Java object with vavr list.

JavaScript

When I serialize the object objectwriter.writeValueAsString(currentDossier) and print the values then in the JSON output I see,

JavaScript

where remarks is a vavr list field inside the object.

Now if I try to deserialize the same value into the object objectMapper.readValue(json, Customer.class) then I get error:

JavaScript

Why is the seralized JSON text not working when trying to deserialze?

JavaScript

Is there any other way in the Java code to print vavr object in textual format and convert it back to POJO?

Advertisement

Answer

You can easily serialize/deserialize vavr objects to/from JSON with jackson. What you need to do is to register VavrModule on the instance of the ObjectMapper:

JavaScript

To get VavrModule you need to add the dependency to vavr-jackson

EDIT

Here you can find a complete working example:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement