I'm getting the following error and no resolution i found did the trick for me:
Unrecognized field "GaugeDeviceId" (Class GaugeDevice), not marked as ignorable
The problem seems, that the service returns the property names with a leading upper letter, while the class properties begin with a lower letter.
I tried:
@JsonProperty("SerialNo")
to the property instantiation - same error@JsonProperty("SerialNo")
to the corresponding getters - same error@JsonProperty("SerialNo")
to the corresponding setters - same error@JsonProperty("SerialNo")
to all of them (just for fun) - same error(note: @JsonProperty("SerialNo")
is just an example)
The strange thing is, that annotation: @JsonIgnoreProperties(ignoreUnknown = true)
should suppress exactly that error, but it is still triggering...
here the Class: (note: not complete)
@JsonIgnoreProperties(ignoreUnknown = true)
public class GaugeDevice
{
private int gaugeDeviceId;
private Date utcInstallation;
private String manufacturer;
private float valueOffset;
private String serialNo;
private String comment;
private int digitCount;
private int decimalPlaces;
@JsonProperty("SerialNo")
public String getSerialNo() {
return serialNo;
}
public void setSerialNo(String serialNo) {
this.serialNo = serialNo;
}
@JsonProperty("Comment")
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
Where is the way out here? Please help.
edit:
Here is the Client Class: (just a simple test client)
import ccc.android.meterdata.*;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import org.glassfish.jersey.jackson.JacksonFeature;
public class RestClient
{
private String connectionUrl;
private javax.ws.rs.client.Client client;
public RestClient(String baseUrl) {
client = ClientBuilder.newClient();;
connectionUrl = baseUrl;
client.register(JacksonFeature.class);
}
public GaugeDevice GetGaugeDevice(int id){
String uri = connectionUrl + "/GetGaugeDevice/" + id;
Invocation.Builder bldr = client.target(uri).request("application/json");
return bldr.get(GaugeDevice.class);
}
}
I hope the error has its root here?
You can ignore the unrecognized fields by configuring the ObjectMapper class: mapper. configure(DeserializationFeature. FAIL_ON_UNKNOWN_PROPERTIES, false);
If the JSON string consists of properties that cannot be mapped to java class attributes, then we encounter UnrecognizedPropertyException.
If there are fields in Java objects that do not wish to be serialized, we can use the @JsonIgnore annotation in the Jackson library. The @JsonIgnore can be used at the field level, for ignoring fields during the serialization and deserialization.
@JsonProperty is used to mark non-standard getter/setter method to be used with respect to json property.
I had the same issue and I resolved it by changing the annotation import from:
com.fasterxml.jackson.annotation.JsonIgnoreProperties
to
org.codehaus.jackson.annotate.JsonIgnoreProperties
Didn't have to define any NamingStrategy or ObjectMapper.
I had the same issue and solved it by changing the annotation import from
com.fasterxml.jackson.annotation.JsonProperty
to
org.codehaus.jackson.annotate.JsonProperty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With