tutorial - object to json java
Json a Gson-Modelado (1)
Aqui tienes.
import java.io.FileReader;
import java.util.List;
import com.google.gson.Gson;
public class Foo
{
public static void main(String[] args) throws Exception
{
Gson gson = new Gson();
Thing[] things = gson.fromJson(new FileReader("input.json"), Thing[].class);
System.out.println(gson.toJson(things));
}
}
class Thing
{
String id;
String name;
String[] object1;
List<String> object2;
}
Estoy tratando de convertir un JSON a GSON, pero no puedo modelar. ¿Alguien puede darme un ejemplo con este?
[
{
"id": "1",
"name": "lalala",
"object1": [
"string1",
"string1",
"string1"
],
"object2": [
"anotherString1",
"anotherString2"
]
},
{
"id": "2",
"name": "laaaaalala",
"object1": [
"string1",
"string1",
"string1"
],
"object2": [
"anotherString1",
"anotherString2"
]
}
]
Gracias