Skip to content

Tag: gson

“Expected BEGIN_OBJECT but was STRING at line 1 column 1”

I have this method: And I want to parse a JSON with: But I get an error message: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 Answer Even without seeing your JSON string you can tell from the error message that it is not the corr…

GSON Integer to Boolean for Specific Fields

I’m dealing with an API that sends back integers (1=true, other=false) to represent booleans. I’ve seen this question and answer, but I need to be able to specify which field this should apply to, since some times an integer is actually an integer. EDIT: The incoming JSON could possibly look like …

Store JSON data in Java

I want to learn JSON data storage in Java using Eclipse, so I googled a lot. I found JSON.simple and GSON. Are those a good choice? I went to Properties >> Java Build Path >> Add External JARs. I added json-simple-1.1.1.jar and google-gson-2.2.4-release.zip. Is it right? Where is the JavaDoc locat…

GSON – Date format

I’m trying to have a custom date format in Gson output, but .setDateFormat(DateFormat.FULL) doesn’t seem to work and it the same with .registerTypeAdapter(Date.class, new DateSerializer()). It’s like Gson doesn’t care about the object “Date” and print it in its way. How can…

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string can look like: In this string every JSON object contains an array of other JSON objects. The intention is to …