I am calling a service which returns responses as json and turn them into a Java object using Gson. In 47 of 50 cases, I get the Java object however in 3 of the cases, I get the following error:
com.google.gson.JsonSyntaxException: Expecting number, got: STRING
at com.google.gson.internal.bind.TypeAdapters$11.read(TypeAdapters.java:304)
at com.google.gson.internal.bind.TypeAdapters$11.read(TypeAdapters.java:293)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.Gson.fromJson(Gson.java:795)
at com.google.gson.Gson.fromJson(Gson.java:761)
at com.google.gson.Gson.fromJson(Gson.java:710)
at com.google.gson.Gson.fromJson(Gson.java:682)
One json response which is failing can be seen here: http://ec2-50-112-212-186.us-west-2.compute.amazonaws.com/ske.json. My Java bean is the following:
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class WordSketch{
@SerializedName("Gramrels")
private List<Gramrel> gramrels;
public List<Gramrel> getGramrels(){
return this.gramrels;
}
public void setGramrels(List<Gramrel> gramrels){
this.gramrels = gramrels;
}
public static class Gramrel {
@SerializedName("Words")
private List<Word> words;
private Number count;
private String name;
private Number score;
private Number seek;
public List<Word> getWords(){
return this.words;
}
public void setWords(List<Word> words){
this.words = words;
}
public Number getCount(){
return this.count;
}
public void setCount(Number count){
this.count = count;
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
public Number getScore(){
return this.score;
}
public void setScore(Number score){
this.score = score;
}
public Number getSeek(){
return this.seek;
}
public void setSeek(Number seek){
this.seek = seek;
}
}
public static class Word {
private Number count;
private Number id;
private String lempos;
private Number score;
private Number seek;
private String word;
public Number getCount(){
return this.count;
}
public void setCount(Number count){
this.count = count;
}
public Number getId(){
return this.id;
}
public void setId(Number id){
this.id = id;
}
public String getLempos(){
return this.lempos;
}
public void setLempos(String lempos){
this.lempos = lempos;
}
public Number getScore(){
return this.score;
}
public void setScore(Number score){
this.score = score;
}
public Number getSeek(){
return this.seek;
}
public void setSeek(Number seek){
this.seek = seek;
}
public String getWord(){
return this.word;
}
public void setWord(String word){
this.word = word;
}
}
}
and the actual gson call is gson.fromJson(json, WordSketch.class).
Could anyone point out what is wrong or at least give me some light as to how to debug (quickly) since I don't know in which part of the json, gson is failing?
Thanks a lot,