Skip to content
Advertisement

Jackson Json Deserialisation: Unrecognized field “…” , not marked as ignorable

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:

  1. changing the propertyNames to first upper letter – same error
  2. adding @JsonProperty("SerialNo") to the property instantiation – same error
  3. adding @JsonProperty("SerialNo") to the corresponding getters – same error
  4. adding @JsonProperty("SerialNo") to the corresponding setters – same error
  5. adding @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?

Advertisement

Answer

Another thing to check out is PropertyNamingStrategy, which would allow Jackson to use “Pascal naming” and match JSON properties with POJO properties. See f.ex here: http://www.javacodegeeks.com/2013/04/how-to-use-propertynamingstrategy-in-jackson.html

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement