简体   繁体   English

将Jackson序列化对象反序列化为Map <String, Object> ?

[英]Deserialize a Jackson serialized object to Map<String, Object>?

I have a string created via objectWriter.writeValueAsString() from an object annotated with Jackson's @JsonType and with fields annotated with @Json that themselves may be @JsonType objects. 我有一个通过objectWriter.writeValueAsString()从对象创建的字符串,该对象带有Jackson的@JsonType注释,并且带有@Json注释的字段本身可能是@JsonType对象。 After the serialization, I'd like to deserialize it to various environments where some of the values may need to be filtered/adjusted. 序列化之后,我想将其反序列化到可能需要过滤/调整某些值的各种环境中。 To do this, I'd like to deserialize the base object into a recursive Map with each member field being a Map if they are a @JsonType, or their native type if not. 为此,我想将基础对象反序列化为递归Map,如果每个成员字段都是@JsonType,则每个成员字段为Map,否则为本地类型。 I can then apply some filters to that resultant map, delete branches, fix values etc, before serializing/deserializing it back to it's final format. 然后,在将其序列化/反序列化为最终格式之前,我可以将一些过滤器应用于该结果映射,删除分支,修复值等。

I've looked into the Polymorphic Deserialization, but doesn't seem to be what I need. 我已经研究了多态反序列化,但似乎并不是我所需要的。

Is there an easy way to do this without actually creating the @JsonType'ed objects? 有没有一种简单的方法,而无需实际创建@ JsonType'ed对象?

Thanks! 谢谢!

It would help if you posted example code. 如果您发布示例代码,将有所帮助。 But you can just write a custom deserializer : 但是您可以编写一个自定义反序列化器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM