0

I have to deserialize a Class in third-party jar that contains a Map<String,Object> Collection property, so that the Annotation @JsonDeserialize cannot be used to defined at the property level, I find that ObjectMapper can be registered with the custom deserializer, like

   ObjectMapper mapper = new ObjectMapper();
   SimpleModule module = new SimpleModule();
   module.addDeserializer(X.class, new XDeserializer());
   mapper.registerModule(module);

   X x = mapper.readValue(json, X.class); 

but this is for class, is there any way to register a custom deserializer for property?

  • So, you would like to deserialise it to a `Map`?. Take a look at [Deserializing into a HashMap of custom objects with jackson](https://stackoverflow.com/questions/18002132/deserializing-into-a-hashmap-of-custom-objects-with-jackson/18014407#18014407) – Michał Ziober Feb 03 '23 at 16:45
  • no, X is class which contains a Map property like this `Class x {Map attributes;....}` – fullstack.yang Feb 03 '23 at 16:50
  • and I just want to make a custom deserializer for this map property, while other properties in this class should use the default Deserialization – fullstack.yang Feb 03 '23 at 16:54
  • Try to use `MixIn` feature [Dynamic addition of fasterxml Annotation?](https://stackoverflow.com/questions/25290915/dynamic-addition-of-fasterxml-annotation/25306786#25306786), [Jackson parse json with unwraping root, but without ability to set @JsonRootName](https://stackoverflow.com/questions/19568867/jackson-parse-json-with-unwraping-root-but-without-ability-to-set-jsonrootname/19600499#19600499), [What is equivalent code settings for @JSonIgnore annotation?](https://stackoverflow.com/questions/16939333/what-is-equivalent-code-settings-for-jsonignore-annotation/16942045#16942045) – Michał Ziober Feb 03 '23 at 16:57

0 Answers0