0

I have a simple class:

@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();
    }

}

I get the following error when trying to deserialize:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "uri" (class com.example.server.telephony.endpoint.Endpoint), not marked as ignorable (5 known properties: "id", "label", "callerId", "phoneNumber", "user"])

Since URI is a generated value there is no field to annotate with @JsonIgnore. Any suggestions on what to do in this case?

Sarah Aziziyan
  • 498
  • 9
  • 22
Leon Roy
  • 580
  • 1
  • 5
  • 16

1 Answers1

1

Annotate your Endpoint class using @JsonIgnoreProperties(ignoreUnknown = true)

Or configure the ObjectMapper with the following option to affect all POJOs deserialized with this Mapper:

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Marc Nuri
  • 2,729
  • 1
  • 14
  • 18