A helpful reference은 StaxMan에 의해 제공됩니다. 아래에 표시된 간단한 예는 다음과 같습니다.
public class Address {
private String address;
private String city;
private String state;
private String zip;
// Constructors, getters/setters
}
public class Location {
private boolean needsRecoding;
private Double longitude;
private Double latitude;
private Address humanAddress;
public Location() {
super();
}
@JsonCreator
public Location(
@JsonProperty("needs_recoding") boolean needsRecoding,
@JsonProperty("longitude") Double longitude,
@JsonProperty("latitude") Double latitude,
@JsonProperty("human_address") Address humanAddress) {
super();
this.needsRecoding = needsRecoding;
this.longitude = longitude;
this.latitude = latitude;
this.humanAddress = humanAddress;
}
// getters/setters
}
또는 JSON 개체 트리에 직접 내용을 역 직렬화 할 수 있습니다. Location
클래스의 예를 약간 수정하여 아래에 설명되어 있습니다.
public class Location {
private boolean needsRecoding;
private Double longitude;
private Double latitude;
// Note the use of JsonNode, as opposed to an explicitly created POJO
private JsonNode humanAddress;
public Location() {
super();
}
@JsonCreator
public Location(
@JsonProperty("needs_recoding") boolean needsRecoding,
@JsonProperty("longitude") Double longitude,
@JsonProperty("latitude") Double latitude,
@JsonProperty("human_address") JsonNode humanAddress) {
super();
this.needsRecoding = needsRecoding;
this.longitude = longitude;
this.latitude = latitude;
this.humanAddress = humanAddress;
}
// getters/setters
}
어디에서 코드를 사용할 수 있습니까? 어노테이션이 필요 없으며 속성에서 적절한 빈 참조 만 필요합니다. –
생성자에서 사용하고 있습니다 – Hank