class Apple{
@JsonProperty("colour")
public String colour;
@JsonProperty("dummy_params")
public DummyParams dummyParams;
}
public abstract class AppleMixin{
@JsonIgnore
@JsonProperty("dummy_params")
public DummyParams dummyParams;
}
我试图在使用objectmapper时忽略dummyparams字段
class Tester{
public static void main(){
Apple app = new Apple();
app.setColor("red");
app.setDummyParams(new DummyParams("1","2"));
ObjectMapper objecMapper = new ObjectMapper();
objecMapper.addMixIn(Apple.class, AppleMixin.class);
String result = objecMapper.writeValueAsString(exec);
}
}
我正在使用com.fasterxml.jackson.databind.objectmapper
预期结果:{“colour”:“red”}
实际结果:{“colour”:“red”,“dummyparams”:{“dummyone”:1,“dummytwo”:2}}
混音器坏了。我做错了吗?
暂无答案!
目前还没有任何答案,快来回答吧!