Networking · interview question
How can you configure the ObjectMapper to handle a JSON input with unknown properties gracefully?
Multiple choiceMediumchapter-11-curatedpremiumnetworkingjackson-objectmapper
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);Answer and explanation
Correct answer
B. ObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Why
By setting FAIL_ON_UNKNOWN_PROPERTIES to false, the ObjectMapper will ignore any JSON properties that don't match the fields in your Java class, preventing exceptions during deserialization.
Test yourself on Networking
A free test with instant, explained results. No account needed.
More Networking questions
- What does the HttpClient.newHttpClient() method do?
- Why is it useful to configuring FAIL_ON_UNKNOWN_PROPERTIES to false in Jackson's ObjectMapper?
- How would you explain a common issue when using ObjectMapper to deserialize nested JSON objects into Java classes in…
- What happens if you attempt to deserialize a JSON array into a Java class with Jackson and FAIL_ON_UNKNOWN_PROPERTIES…
- Why is it important to set timeouts on HTTP requests?
- How would you explain a potential benefit of using CompletableFuture.supplyAsync to fetch data from multiple API…