I have a Java object with vavr list.
@Value
@Builder(toBuilder = true)
public class Customer {
private final List<Remark> remarks;
}
When I serialize the object objectwriter.writeValueAsString(currentDossier)
and print the values then in the JSON output I see,
{ "remarks" : {
"empty" : true,
"lazy" : false,
"async" : false,
"traversableAgain" : true,
"sequential" : true,
"ordered" : false,
"singleValued" : false,
"distinct" : false,
"orNull" : null,
"memoized" : false
}
}
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:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `io.vavr.collection.List`
(no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (String)"{"remarks" : {
Why is the seralized JSON text not working when trying to deserialze?
@Test
public void mapperForVavrList() throws JsonProcessingException {
Customer cus = Customer.builder().remarks(List.empty()).build();
ObjectWriter ow = new ObjectMapper()
.writer().withDefaultPrettyPrinter();
String json1 = ow.writeValueAsString(cus);
log.info(json1);
ObjectMapper objectMapper = new ObjectMapper();
Customer cus2 = objectMapper.readValue(json1, Customer.class);
log.info(cus2.toString());
}
Is there any other way in the Java code to print vavr object in textual format and convert it back to POJO?