{ "age": 25, } import com.google.gson.Gson; public class JsonParsingExample { public static void main(String[] args) { Gson gson = new Gson(); Person person = gson.fromJson(json, Person.class); } } class Person { private String name; private int age; private String city; } import com.google.gson.Gson; public class JsonSerializationExample { public static void main(String[] args) { Person person = new Person(); person.setAge(25); Gson gson = new Gson(); String json = gson.toJson(person); System.out.println(json); } } class Person { private String name; private int age; private String city; } Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new DateSerializer()) .registerTypeAdapter(Date.class, new DateDeserializer()) .create();


上一篇:
下一篇:
切换中文