I want to convert a class which contains a Hashmap of non-primitive keys or values to Json using Gson. so I realize that Hashmap keys and values are stored only as Strings when serializing with Gson. so I can’t serialize them. I ran into this solution which should be fine, but I get this error: any idea? EDIT: this is
Tag: gson
How can I dynamically find the end of an object array inside of a JSON response using GSON?
I am working with a given JSON response. The API I’m using provides responses like such: As you can see, the response provided contains what I interpret to be 1 object array (size changes depending on what is being queried) and 2 objects. (data is the array, meta and links are the objects) I have ran into a situation where
How to read a static file on Heroku deployment on Spring Boot
How can I solve this situation? I have a static JSON file on my src/main/resources and when I run the code, I use this JSON to create some data, but when I try to deploy on heroku I get this error, probably because they couldn’t find the FUNDOS.json file. Does anyone have an idea on how to solve that? Code
Gson to append json object within an array in a json file in java
I am trying to store a game result in a JSON file. The results are stored when the game is over, and are supposed to be displayed afterwards in a table. I have this function that creates the game score and adds it to json file using GSON That method creates a JSON file that looks like this: The problem
Serialize Object/Object[] entries to gson JsonObject
I am reading a resource from a backend that is giving me an Map of entries. I am iterating these and retriving the values. The type of that value is object or object[], the actual types are common primitives or a Calender class. My target is to create a json response, it should look like this: But I am really
How to set the classpath correctly in java
I need to compile and run simple code using the gson library, but I can’t use Maven, Gradle or the IDE. The directory contains Main.java and gson-2.9.0.jar javac -cp gson-2.9.0.jar Main.java works correctly and creates Main.class But when I run java -cp ./*: Main, I get I also tried the following commands: But all these commands give the same result.
Streaming large JSON from input stream efficiently in Java
In order to save memory and avoid an OOM error, I want to stream a large JSON from an input stream and extract the desired things from it. More exactly, I want to extract and save some strings from that JSON: files.content.fileContent.subList.text = “some text in file” files.content.fileContent.subList.text = “some text in file2” and save them into a String variable:
Java Date to MongoDB date with Gson
Introduction I am currently working on a project that regularly saves several java objects to a MongoDB database. This object contains a Date. Problem The conversion of java Date to Json Mongo give this: But this format does not conform with MongoDB Date. MongoDB is considered as a string instead of a Date. Affected code Question How to create an
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 39 path $.message
i am making login function in android using retrofit. I have created an endpoint for login validation, then I have tested it using Postman using raw (json) and it worked. But when I enter the endpoint into android using retrofit I get an error message like this: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 39
GSON flat down map to other fields
So I have an Android app which uses Retrofit for API. I have a class like which looks like: When GSON creates a JSON it looks like: Would it be possible to change JSON serialization to: Thanks. Answer Here is how Gson could be used to implement the flattening: I’ve put some comments explaining “whats” and “hows”. But it would