com.fasterxml.jackson(.databind) v3 has issues deserializing `java.util.Properties` (this had worked in v2)

22 hours ago 2
ARTICLE AD BOX

In my Java application I had the requirement to implement a "hierarchical HashMap", meaning: I have a hierachy of HashMaps (each containing name-value pairs) which are connected in a tree-like fashion and behave such, that if a key is not found in the local map, they check for that key in their "parent-map" (recursively up to a root-map) and - if they find one, they provide that "upper" map's value.

Back then I decided to use "java.util.Properties" (or to be precise: a class deriving from Properties) for that purpose since these implement exactly such a map-hierachy: when creating a new Properties-instance you can provide a parent-Properties-instance.

I am (de-)serializing these properties to/from JSON using the com.fasterxml.jackson(.databind)-library (com.fasterxml.jackson.databind.json.JsonMapper). This had worked without any issue with Jackson v2, but now I just upgraded to Jackson v3 and with that version the deserialization of Properties fails. :-(
When trying to reading JSON files created by the earlier version I keep getting errors:

File 'test.kmc' is not a valid configuration (reason: 'com.fasterxml.jackson.databind.JsonMappingException: Problem deserializing property 'properties' (expected type: [map type; class my.application.entities.NodeProperties, [simple type, class java.lang.String] -> [simple type, class java.lang.String]]; actual type: `java.util.Properties`), problem: argument type mismatch at [Source: (BufferedInputStream); line: 8, column: 2] (through reference chain: my.application.entities.nodes.RootNode["properties"])

Note: class NodeProperties is a simple class that derives from java.util.Properties like so:

public class NodeProperties extends Properties { ... }

and simply adds a few additional operations I needed for my name-value-pair hierachies.

Any idea anyone, why Jackson's deserialization of java.util.Properties fails in version 3.x? Is that expected behavior? Is there now some flag or helper required for this?

Read Entire Article