import com.google.gson.Gson;
public class Main {
public static void main(String[] args) {
String json = "{\"name\":\"John\", \"age\":30, \"city\":\"New York\"}";
Gson gson = new Gson();
Person person = gson.fromJson(json, Person.class);
System.out.println(person.getName());
}
}
class Person {
private String name;
private int age;
private String city;
}
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
String json = "{\"name\":\"John\", \"age\":30, \"city\":\"New York\"}";
ObjectMapper objectMapper = new ObjectMapper();
Person person = objectMapper.readValue(json, Person.class);
System.out.println(person.getName());
}
}
class Person {
private String name;
private int age;
private String city;
}
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Main {
public static void main(String[] args) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat("yyyy-MM-dd");
gsonBuilder.serializeNulls();
Gson gson = gsonBuilder.create();
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
}