Search code examples
javajsonjacksondeserialization

Jackson deserialization specific getter turning off


What is the most simple way to tell the Jackson to not serialize a specific getter method? I only want to say explicit to one getter, because I have a custom, complex class, and all setter and getter should function, only one should not:

mapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, true);

So this is not the proper way. I need to tell that I don't want to use the getter in this class:

public static class EventRow implements Serializable, Cloneable, GRSerializable {
    public int x
    public int y
    public double z
    public String eventKeyValuesPacked; 

    //This getter should not be used, because there is no explicit setter
    //for    this, and also no public... And it is only unpack  
    //EventKeyValuesPacked so it would be multiple data...
    public KeyValue[] getEventKeyValues() {
       KeyValue[] kvs = DA_EventKey.unpackKeyValues(eventKeyValuesPacked);
       return kvs == null ? new KeyValue[0] : kvs;
   }
}

Is there any annotation or SerializationConfig option to make invisible the getEventKeyValues() getter method?


Solution

  • There is an annotation for this: @JsonIgnore.

    @JsonIgnore
    public KeyValue[] getEventKeyValues() {
    ...
    

    If you don't want to use an annotation for this then you'll need to write a custom serializer.