I am using Java 17, spring-boot 2.6.3 with spring-webflux and spring-consul dependencies and I have the following class: Here’s my custom serializer. And my models are as simples as this: I can’t annotate my model class with @JsonSerialize(using = ModelSerializer.class) because it is in a dependen…
Tag: jackson2
Jackson serialize nested attribute with same name
Currently, I have a JSON response of the following type. I want to map my custom class to nested user attributes. But when I am trying to get the attribute, it is always sending null value. I think it is maping to first occurance of “user” in line no 2. How can I map it to correct user attribute i…
Jackson deserialization using JsonParser distinguish between the direct object and objects within array
I am using the Jackson for the Deseilization of the JSON. The Deseilization works perfectly for a JSON with CustomerDocument. However, I have a new requirement in which I need to find whether provided JSON has CustomerDocument or just Customer. I am able to develop the logic for both but the problem is that w…
Copy all values List to Jackson JsonGenerator Array directly instead of looping over it
I am creating a JSON file using the Jackson JsonGenerator for which I need to add the elements from List<String>. This List consists of the JSON Fragments which needs to be added to my final JSON file. As of now, I am looping over the List<String> and adding them to my Jackson JsonGenerator writeR…
‘com.google.api.client.json.jackson2.JacksonFactory’ is deprecated. What are my options?
While following the Gmail API java quickstart guide I came across this code snippet: Using it in the editor gave me a warning that it is deprecated. What are my options? Answer Look up the API documentation of class JacksonFactory. It tells you what to do: Deprecated. use com.google.api.client.json.GsonFactor…
Jackson , java.time , ISO 8601 , serialize without milliseconds
I’m using Jackson 2.8 and need to communicate with an API that doesn’t allow milliseconds within ISO 8601 timestamps. The expected format is this: “2016-12-24T00:00:00Z” I’m using Jackson’s JavaTimeModule with WRITE_DATES_AS_TIMESTAMPS set to false. But this will print mill…
What is the difference between ObjectNode and JsonNode in Jackson?
According to the documetation of JsonNode: Most mutators, however, need to be accessed through specific sub-classes (such as ObjectNode and ArrayNode). However I am still confused since some stackoverflow answers seem to use them quite interchangeably. What different purpose do they serve? Answer JsonNode is …