Hi there,
I also have a question about the @JsonIgnoreProperties
annotation.
Iāve been modifying the example located at Bitbucket to test REST v2 behavior in various scenarios.
However, Iāve encountered some issues. It seems like @JsonIgnoreProperties(ignoreUnknown = true)
isnāt working as expected, or perhaps Iām missing something.
Question:
Is this behavior something that requires configuration on your end?
The similar annotation from the codehaus library works as expected, out of the box.
Example:
package com.atlassian.plugins.rest.sample.v2.marshalling.mediatypes.json;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true)
public class JsonElementPojo {
private String elementDescription;
private Integer elementValue;
}
package com.atlassian.plugins.rest.sample.v2.marshalling.mediatypes.json;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true)
public class JsonPojo {
private String description;
private Integer value;
private JsonElementPojo element;
private List<JsonElementPojo> elements;
}
package com.atlassian.plugins.rest.sample.v2.marshalling.mediatypes;
import com.atlassian.plugins.rest.api.security.annotation.UnrestrictedAccess;
import com.atlassian.plugins.rest.sample.v2.marshalling.mediatypes.json.JsonElementPojo;
import com.atlassian.plugins.rest.sample.v2.marshalling.mediatypes.json.JsonPojo;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Arrays;
import java.util.List;
@Path("entity")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
public class EntityResource {
//...
@POST
@Path("/json")
@UnrestrictedAccess
@Consumes(MediaType.APPLICATION_JSON)
public JsonPojo postJsonTypeOnlyJsonPojo(JsonPojo jsonPojo) {
return jsonPojo;
}
}
Request body
{
"description": "Set Example returned JaxbPojo",
"value": 123,
"element": {
"elementDescription": "Set Element in Root",
"elementValue": 123
},
"elements": [
{
"elementDescription": "Set Element 1",
"elementValue": 123
},
{
"elementDescription": "Set Element 2",
"elementValue": 123
}
],
"shoudBeIgnored1": "ignored value",
"shoudBeIgnored2": [
"ignored value 1", "ignored value 2"
]
}
Response body
Unrecognized field "shoudBeIgnored1" (class com.atlassian.plugins.rest.sample.v2.marshalling.mediatypes.json.JsonPojo), not marked as ignorable (4 known properties: "value", "description", "elements", "element"])
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 18, column: 25] (through reference chain: com.atlassian.plugins.rest.sample.v2.marshalling.mediatypes.json.JsonPojo["shoudBeIgnored1"])
Regards,
RafaÅ