Jackson FAIL_ON_UNKNOWN_PROPERTIES

Elvis Ciotti
Aug 8, 2023

--

By setting FAIL_ON_UNKNOWN_PROPERTIES to false, you are telling Jackson that if it encounters any unknown properties in the JSON data, it should ignore them and continue with the deserialization process without raising an exception. This can be useful in cases where you have JSON data with extra fields that you don’t need or care about in your Java objects.

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

public class Main {
public static void main(String[] args) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

// Now you can use the objectMapper to deserialize JSON data without failing on unknown properties.
}
}

--

--

Elvis Ciotti
Elvis Ciotti

Written by Elvis Ciotti

Software Contractor — Java, Spring, k8s, AWS, Javascript @ London - hire me at https://elvisciotti.github.io/

No responses yet