0

I want to be able to do something with the totalNumber in the JSON before assigning it to the TotalNumber object. Is there a way to do that with Jackson?

public class Numbers
{
  private TotalNumber totalNumber;
}


[{
  "totalNumber": [1,2,3,4]
}]
Jon
  • 453
  • 5
  • 18
  • 2
    What is that "something" that you want to do? You could implement a custom serializer to do some operations with the data, but manipulating the raw JSON is a big no-no. – Dropout Mar 03 '21 at 13:48
  • Its just some generic example, but I may want to do some manipulation to the data before mapping it to the field. It was hoping that I can just do something in the constructor, but it seems like the custom serializer is the way. – Jon Mar 03 '21 at 13:56
  • 1
    I'm working on an example, give me a second please – Dropout Mar 03 '21 at 14:19
  • 1
    I'm kind of playing around with an idea of just deserializing the JSON into the actual object that the JSON represents, some `NumbersDTO`, using the default deserializer that Jackson provides and then actually transforming the object to another one that is to your liking, so you're actually doing the transformation from object to object. That would avoid using a custom deserializer. Unfortunately something came up for me and I need to go, but if you wish to make the custom deserializer then here's a link https://www.baeldung.com/jackson-deserialization, hope it helps – Dropout Mar 03 '21 at 14:33

0 Answers0