How to map JSON object with slashes in field name?

I am self-learned beginner in Java coding so please be understanding. I am writing REST api app that at some point expects to get such response from server: [ { "success": { "/config/linkbutton": true } } ] Normally I would create specific object with field named after my expected response and I would map this… Read More How to map JSON object with slashes in field name?

Convert JSON to MAP using GSON library

I want to convert JSON response to Map what is the best approach to get the desired output using GSON library. I try this and I’m getting only the ArrayList value. Map<String, Object> map = gson.fromJson(response, HashMap.class); ArrayList responseOptions = (ArrayList) map.get("data"); output: [{language=Java, value=8}, {language=Ruby, value=7}, {language=Python, value=7}] Sample JSON Response { "data":[ {… Read More Convert JSON to MAP using GSON library

How do I write a JSON file using GSON in the resources folder without using src/main/resources?

I’m trying to write a JSON file with GSON in the resources folder without using src/main/resources: package repository; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import org.tinylog.Logger; import java.io.*; import java.util.List; public class GsonRepository<T> extends Repository<T> { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public GsonRepository(Class<T> elementType) { super(elementType); } public void saveToFile(String resourceName) throws… Read More How do I write a JSON file using GSON in the resources folder without using src/main/resources?

Unable to convert class to JSON using GSON

When i’m trying to convert an object in my Android App to a Json i get the following error: class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations The issue is that in some devices all is working GSON version: implementation ‘com.google.code.gson:gson:2.9.0’ implementation ‘com.squareup.retrofit2:converter-gson:2.9.0′ While the code i’m trying to convert the object is the following:… Read More Unable to convert class to JSON using GSON

How to structure class for deserializing this nested array?

I’m trying to deserialize a nested array from a JSON response. It’s the first time I’ve ever gotten an array of arrays and I’m not quite sure how to structure my class to handle it. { "prices": [ [ 1641670404234, 0.01582586939240936 ], [ 1641674037525, 0.015999047707867396 ], [ 1641677655158, 0.016072905257982606 ] … ], } If the… Read More How to structure class for deserializing this nested array?