Skip to content
Advertisement

Tag: gson

JSON Error “java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $”

This create Exception Big thanks for help. Answer Let’s look at the error you are receiving. Expected BEGIN_OBJECT Your JSON is an object, and all JSON objects are enclosed in curly braces ({}). BEGIN_OBJECT is therefore {. And it’s expecting it somewhere. but was STRING But instead he found a string “Something”. Still doesn’t tell us where. at line 1

“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 correct structure to be parsed into an instance of your class.

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 this (could also be String instead of int, etc…):

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 located? Main problem concerns an example found here: JSON.simple example

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 I change that? Thanks EDIT: I always use java.util.Date; setDateFormat() doesn’t work 🙁 Answer It seems that you

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 extract a list of IDs

Advertisement