javajacksonfasterxml

JavaPropsMapper in com.fasterxml.jackson version 2.14.2


I did an upgrade of com.fasterxml.jackson from 2.8.8 to 2.14.2 but I noticed that the following code will not work in version 2.14.2 :

 //where javaPropsMapper is an instance of com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper;
 // and Properties is from java.util.Properties

 Properties prop = new Properties();
 properties.setProperty("a.key", "value");
 JsonNode result = javaPropsMapper.readValue(prop, JsonNode.class);

the above code in version 2.14.2 does not compile because there is no method javaPropsMapper.readValue that accepts these arguments anymore.

In version 2.8.8 the output would be a JsonNode like this: {"a":{"key":"value"}}

Please let me know if you have any hints/info or an alternative way to do it. Thanks a lot


Solution

  • Use

    public <T> T readPropertiesAs(Properties props,
                         Class<T> valueType)
                       throws IOException
    

    Full example