2017-10-11 5 views
0

없는 필드에 생성 된 값을 처리 :잭슨 직렬화 - 나는 간단한 클래스가

com.fasterxml.jackson.databind을 : 역 직렬화 할 때

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Endpoint.class) 
public class Endpoint { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @JsonView({View.Endpoint.class, View.User.class}) 
    private Long id; 

    @NotNull 
    @NotEmpty(message = "Phone number is required.") 
    @JsonView({View.Endpoint.class, View.Call.class, View.User.class}) 
    private String phoneNumber; 

    @JsonView({View.Endpoint.class, View.Call.class, View.User.class}) 
    private String callerId; 

    @ManyToOne(optional = false) 
    @JsonView(View.Endpoint.class) 
    @ApiModelProperty(hidden = true) 
    private User user; 

    ... 

    @Override 
    @JsonView({View.Endpoint.class, View.Call.class, View.User.class}) 
    public String getUri() { 
     return EndpointController.BASE_PATH + "/" + getId(); 
    } 

} 

나는 다음과 같은 오류가 발생합니다. exc.UnrecognizedPropertyException : 인식 할 수없는 필드 "uri"( com.example.server.telephony.endpoint.Endpoint)는 으로 표시되지 않습니다 ignorable (알려진 속성 5 가지 : "id", "label", "callerId", " phoneNumber ","user "])

URI는 생성 된 값이므로 @JsonIgnore으로 주석을 추가 할 필드가 없습니다. 이 경우해야 할 일에 대한 제안 사항은 무엇입니까?

+0

당신은 고려할 수를 [믹스 인을 (https : //로 stackoverflow.com/a/38889775/1426227). –

+0

@JsonIdentityInfo를 사용할 때 –

+0

필드 대신 getter 주석 달기를 시도하십시오. @JsonView가 있어야하는 것은 무엇입니까?! – Generic

답변

0

@JsonIgnoreProperties(ignoreUnknown = true)

를 사용하여 Endpoint 클래스를 주석 또는이 매퍼 직렬화 모든 POJO에 영향을 줄 수있는 다음과 같은 옵션으로 ObjectMapper을 구성

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);