Next, create a Java source file with the following contents:
import com.google.gson.Gson; public class SimpleTest { static class TestObj { int value1 = 1; String value2 = "abc"; } public static void main(String[] args) { Gson gson = new Gson(); TestObj[] objs = new TestObj[3]; for (int i = 0; i < objs.length; ++i) objs[i] = new TestObj(); ListSave it to c:\temp\SimpleTest.javaobjs2 = new ArrayList (); objs2.add(objs[0]); objs2.add(objs[1]); objs2.add(objs[2]); System.out.println(gson.toJson(objs)); System.out.println(gson.toJson(objs2)); } }
Then compile it: