M
M
mokrosoft2018-04-25 21:21:05
Java
mokrosoft, 2018-04-25 21:21:05

Java Gson how to organize different objects?

Hello.

status: "ok"
data: [
  {
  name: name1,
  description: asdfasdfasdf
  items:
    [
      {
      name: name
      }
    ]
  },
  
  {
  name: name1,
  description: asdfasdfasdf
  items:
    [
      {
      name: name,
      desc: 32
      age: 123123
      }
    ]
  }
  }
]

Class1 class1 = new Gson.fromJson(response, Class1.class);

I describe it in classes, tell me how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Astakhov, 2018-05-03
@mytoffnax

public class Class1 {
  private String status;
  private List<Class2> data;
}
public class Class2 {
  private String name;
  private String description;
  private List<Item> items;
}
public class Item {
  private String name;
}

Not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question