Skip to content

Tag: gson

Object not being able to map to POJO class

I am getting a response, which I converted to Pojo class with one field of type Object. Now when I am trying to cast the Object type to another Pojo class its throwing the error : Code : Here, firsClass object when printed gives following result : Now, the error happens in the following line : I am sharing th…

Gson Failing to call custom Serializer

I’ve been trying to follow the advice given here to turn off scientific notation on numeric values represented in Json. The problem I’ve got is that my custom Serializer is never called. I’ve tried different variations of the code and have eventually ended up with: If I’ve understood t…

Connect two HashMap Values

I’ve got this JSON string: String json = “{“countries”:{“2″:”China”,”3″:”Russia “,”4″:”USA”},”capitals”:{“2″:Beijing,”4″:null,”3″:Moscow}}”; I converted string …

How to avoid Jackson escaping double quotes in Java?

I am working on a project and wanted to rewrite some code written in Gson to Jackson using ObjectMapper. So I am trying to create a JSON string using some properties as below: Expected result: Actual: So once I create a JSON String using Jackson, it turns out it is escaping double quotes for field names and v…

GSON – trim string during deserialization from JSON

I have a JSON string that is parsed using the GSON library into a Map like so: The problem I have is, my JSON attribute values have trailing/leading whitespaces that needs to be trimmed. Ideally, I want this to be done when the data is parsed to the Map using GSON. Is something like this possible? Answer You …

Serializing JSON with class metadata

I’ve used both Gson and Jackson and both of them offer a way to deal with polymorphism. For example, with Jackson you need to declare the class with a @JsonSubTypes and add each and every @JsonSubTypes.Type you have. Similar thing happens with Gson. My question is if there is an option to make it work l…

change the json object value

I have a json object like above and i want to change apiInvokerPublicKey’s value i did not find a method in gson so how can i change it? EDIT: I used addProperty method from gson but it changes whole “onboardingInformation” i just want to change “apiInvokerPublicKey” Answer You c…