Edit I've added the details class and fixed the duplicate key. The dates are in fact strings.
Using gson 2.8 and eclipse.
I managed to get the JSON file parsed and the values stored and printed, but I still get the exception. (BEGIN_OBJECT expected but was STRING at line 1 column 2)
I've checked other solutions, like put an object where expected, but it just throws a different exception. e.g (begin_array is expected)
Json File
[{"numValue1":"1",
"StringValue1":"EI",
"StringValue2":"A",
"enumValue1":"TYPE_A",
"numValue2":"3221",
"StringValue3":"DDEF",
"StringValue4":"Mexicof",
"numValue3":"8",
"stringDate1":"27/05/2017 11:55",
"stringDate2":"29/09/2016 11:55",
"stringDate3":"27/05/2017 11:57"}]
Code used for parsing the file
Gson gson = new GsonBuilder().setDateFormat("dd/MM/yyyy HH:mm").create();
Details[] feedRecord = gson.fromJson(data.trim(), Details[].class);
Details class
public class Details implements Serializable {
enum Type {
TYPE_D, TYPE_A
};
@SerializedName("numValue1")
private Integer num1;
@SerializedName("StringValue1")
private String string1;
@SerializedName("StringValue2")
private String string2;
@SerializedName("numValue2")
private String num2;
@SerializedName("StringValue3")
private String string3;
@SerializedName("StringValue4")
private String string3;
@SerializedName("numValue3")
private String num3;
@SerializedName("StringDate1")
private String date1;
@SerializedName("StringDate2")
private String date2;
@SerializedName("StringDate3")
private String date3;
@SerializedName("enumType1")
private Type enumType;
}
Exception
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $[0]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:852)
at com.google.gson.Gson.fromJson(Gson.java:801)
at com.google.gson.Gson.fromJson(Gson.java:773)