I have an object, which I would like my jackson to serialize. For instance:
public class RaceCar {
public String model;
public Int topSpeed;
}
My difficulty is that I do not want all of my RaceCar's fields to be serialized. I have attempted to cast my object to a superclass which does not not have access to the fields that I want to hide. For instance:
public class Car {
public String model;
}
However, despite the cast, jackson still manages to serialize all of my RaceCar's fields. The output would be:
{"model": "x103", "topSpeed": 200}
Jackson serializes all of my RaceCar's fields even when the RaceCar object is cast to Object. I am guessing that jackson uses some sort of relfection mechanism to bypass my cast. Is there anyway to prevent jackson from bypassing my cast?
Edit: I should have specified that I can not use @JsonIgnore, because in some cases I would like to return the entire object and in others, I would like to return the object with less fields.