与杰克逊一起使用不同配置的父母/子类应对父母/子类
我正在使用带有Spring Boot的Rentful应用程序进行工作,并且我已经定义了我的类,如下所示:
class Organization {
String name;
}
class Base {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
Organization org;
}
class Car extends Base{
//other members
}
class FlattenCar extends Car {
@JsonUnwrapped(prefix = "org_")
Organization org;
}
现在发生的是,对ORG对象的审理取决于第一次调用。这意味着,如果我第一次进行挑选的汽车,那么接下来要打电话给flattencar,反之亦然。 我知道我隐藏了组织成员,但似乎第一次被审理被缓存! 谁知道问题在哪里,我该如何解决?
I'm working on a Restful application with Spring Boot and I've defined my classes as below:
class Organization {
String name;
}
class Base {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
Organization org;
}
class Car extends Base{
//other members
}
class FlattenCar extends Car {
@JsonUnwrapped(prefix = "org_")
Organization org;
}
Now what happened is, deserializing the org object depends on the first time call. It means, if I deserialize Car at the first time, next calls on deserializing FlattenCar doesn't unwrap org and vice versa.
I know that I hid org member, but it seems the first time deserializing is cached!
Who knows where is the problem and how can I resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题似乎是在您的基类中具有read_only(仅用于序列化)的选项,如果只想将此属性考虑到避难所化时。
OUPUT:
请记住,在此示例中,汽车/Carflatten类的TO_STRING方法已继承了基类。
Your problem seems to be that have in your Base class the option READ_ONLY (only for serialization), when it should be WRITE_ONLY if only want to take this property into account in the deserialization.
Ouput:
Remember that Car/CarFlatten class's to_string method has been inherit of Base class in this example.