gson
build.gradle
dependencies 에
implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0'
를 추가해주자
//1)
String jsonInput = "{\"imdbId\":\"tt0472043\",\"actors\":" +
"[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":\"1982-09-21T12:00:00+01:00\"," +
"\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}";
//2)
Movie outputMovie =
// 3)
new Gson().fromJson(jsonInput, Movie.class);
public class CustomDto {
private String number;
private String name;
// 1) Gson 인스턴스 생성
Gson gson = new Gson();
// 2) 객체로 바꿀 문자열 데리고 오기
String json = design.getContent();
// 3) 내가 원하는 객체로 fromJson(문자열, 바꿀객체.class)
DesignContentDto designContentDto =
gson.fromJson(json, DesignContentDto.class);
Both Gson and Jackson are good options for serializing/deserializing JSON data, simple to use and well documented.
Advantages of Gson:
Advantages of Jackson:
코드 및 내용 출처 :
https://www.baeldung.com/jackson-vs-gson