我会用一个
JsonDeserializer。检查相关字段,确定是否为该字段
emtpy并返回
null,因此您
ContainedObject将为null。
这样的东西(半伪):
public class MyDes extends JsonDeserializer<ContainedObject> { @Override public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException { //read the JsonNode and determine if it is empty JSON object //and if so return null if (node is empty....) { return null; } return node; } }然后在您的模型中:
public class Entity { private long id; private String description; @JsonDeserialize(using = MyDes.class) private ContainedObject containedObject; //Contructor, getters and setters omitted }希望这可以帮助!



