Java DeserializerFactoryConfig-class And Method Code Example


Here is an example of using the DeserializerFactoryConfig class from the com.fasterxml.jackson.databind package in the Jackson library for Java:

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.DeserializerFactoryConfig;

public class Example {
    public static void main(String[] args) {
        // create a new ObjectMapper
        ObjectMapper mapper = new ObjectMapper();
        // get the DeserializerFactoryConfig of the mapper
        DeserializerFactoryConfig factoryConfig = mapper.getDeserializationConfig().getDeserializerFactoryConfig();
        
        // configure the factory to disable the use of Java 8 time types
        factoryConfig.without(DeserializationFeature.USE_BIG_DATE_FOR_DATES);

        // example input JSON string
        String jsonInput = "{\"date\":\"2022-01-01\"}";
        try {
            // use the ObjectMapper to deserialize the input JSON to a MyData object
            MyData data = mapper.readValue(jsonInput, MyData.class);
            System.out.println("MyData: " + data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

class MyData {
    private java.util.Date date;

    public java.util.Date getDate() {
        return date;
    }

    public void setDate(java.util.Date date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "MyData [date=" + date + "]";
    }
}

This example uses the DeserializerFactoryConfig class to configure the deserialization factory of an ObjectMapper. It disables the use of Java 8 time types via the without(DeserializationFeature.USE_BIG_DATE_FOR_DATES) method. Then it uses the ObjectMapper to deserialize a JSON input to a MyData object.

Please note that the DeserializerFactoryConfig class is not a public class, it is intended to be used internally by the ObjectMapper, and it's usage may change in future versions of the library.