Linked Questions
13 questions linked to/from Make GSON accept single objects where it expects arrays
1 vote
0 answers
294 views
Gson handle integer or array of integers [duplicate]
I have JSON that may look like this { "endpoint": { "status": "xxxx", "port": [ 123 ], } } or this { "endpoint": { "status": "xxxxxxx", "port": ...
1 vote
0 answers
48 views
Expected a string but was BEGIN_ARRAY - GSON kotlin [duplicate]
I'm fairly new to JSON parsing, I'm using the Retrofit library of Square and ran into this problem. I'm trying to parse this JSON reponse: [{ "contactName":"ABC", "addons"...
30 votes
1 answer
31k views
How do I implement TypeAdapterFactory in Gson?
How do I implement type TypeAdapterFactory in Gson? The main method of create is generic. Why? The registration method registerTypeAdapterFactory() does not receive type a type argument. So, how ...
3 votes
2 answers
4k views
Gson: deserialize objects that can be a single object or an array
I am using Gson to parse a JSON response from a certain API. Everything was working ok, but now seems like one of the fields of the response can come in an array form or in a single element form, so ...
3 votes
3 answers
5k views
How to parse a json response with multi type values coming for same field?
How to parse answerData key from json response in kotlin as it is changing its type in each block? I tried keeping it Any but was not able to type cast. how to parse answerData? { "status": ...
2 votes
2 answers
3k views
How Parse JSON using GSON WHen object is either JSONObject or JSONArray
I am using Gson to convert JSON into a Java object. I have a field in the json that our wise services people coded as either an array or object depending on how many items come back in database. ...
1 vote
1 answer
2k views
Handle dynamic response sometimes object / array on same key on android kotlin
I have a response from this api, and there is different response on ... "value": [ { "@unit": "C", "#text": "28" } ] sometimes &...
1 vote
4 answers
1k views
Gson: How do I parse polymorphic values that can be either lists or strings?
I need to parse a JSON file that contains long list of customers. In the JSON file each customer may have one id as a string: { "cust_id": "87655", ... }, or a few ids as an array: { "...
0 votes
1 answer
231 views
Json string to Object mapping with dynamic values
I am consuming Thirdparty jsonString, I am trying to parse the json but sometimes JSON object "RadarReports" is an list and sometimes it object. {"RadarReports": { "...
0 votes
0 answers
214 views
JSON, data can have object and array and use data class for all
When trying to process JSON, I recive Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 ...
0 votes
2 answers
148 views
Dynamic filtering critieria for post query
I need a dynamic filtering criteria for querying west webservices using post. to give you an example. { "fields": [ "field":"firstName", "field":"lastName" ] ,...
0 votes
2 answers
200 views
Java ignore custom deserialization on GSON if json format is valid
I have been looking around but could not find any conclusion for my problem, I'll try to describe it the best way I can. I'm calling an API that can respond 2 ways (note that class names are only ...
2 votes
1 answer
72 views
APis Retrofit GSON: Datatypes changing all the time
I am using Retrofit with GSON for an app for a client, and I am having some trouble with some of my client APIs and I need to workaround this problem. Let's say i have an API which gives me telephones:...