개발일지/Java
[Java] jackson ObjectMapper
개발자리
2024. 1. 30. 14:50
반응형
Jackson.ObjectMapper 라이브러리
자바 객체와 json 객체사이에서 직렬화, 역직렬화 시켜주는 라이브러리
//객체생성
public class Car {
private String color;
private String type;
// standard getters setters
}
// 직렬화 예시
ObjectMapper objectMapper = new ObjectMapper();
Car car = new Car("yellow", "renault");
objectMapper.writeValue(new File("target/car.json"), car);
//역직렬화 예시
String json = "{ \\"color\\" : \\"Black\\", \\"type\\" : \\"BMW\\" }";
Car car = objectMapper.readValue(json, Car.class);
반응형