0

I have this JSON format:

["com.atlassian.greenhopper.service.sprint.Sprint@60d1cf92[id=636,rapidViewId=69,state=CLOSED,name=ABC-1,startDate=2016-07-18T08:22:00.000-04:00,endDate=2016-07-29T04:15:00.000-04:00,completeDate=2016-08-09T10:34:24.009-04:00,sequence=636]", "com.atlassian.greenhopper.service.sprint.Sprint@461fc487[id=656,rapidViewId=69,state=ACTIVE,name=ABC-2,startDate=2016-08-09T10:42:41.342-04:00,endDate=2016-08-19T06:35:00.000-04:00,completeDate=<null>,sequence=656]"]

I am trying to parse this using Gson parse, but getting this Expected BEGIN_OBJECT but was STRING at line 1 column 3 path $[0].

The Java snippet and a Spring bean used for parsing is below:

Type sprintBeanType = new TypeToken<List<SprintBean>>() {}.getType();
List<SprintBean> sprintBeanList = gson.fromJson(json, sprintBeanType);

public class SprintBean{
    @Expose
    private String sprint;

    public String getSprint() {
        return sprint;
    }

    public void setSprint(String sprint) {
        this.sprint = sprint;
    }

}

Any help in parsing this JSON is highly appreciated.

Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105

1 Answers1

0

Your JSON data looks like it is just a list of strings, so can parse it into a List<String> by replacing the type generic and list var type to List<String>:

Type sprintStringType = new TypeToken<List<String>>() {}.getType();
List<String> sprintStringList = gson.fromJson(json, sprintStringType);

However that only parses the basic JSON data into strings, the "inner" data will not be parsed. Also, you will unlikely be able to parse each string using GSON because it is no valid JSON data.

jCoder
  • 2,289
  • 23
  • 22