Scrivio Interview library

JSON with Jackson

37 questions in 11 subtopics.

ObjectMapper configuration

ConceptFoundations6 min read
How does Spring Boot configure Jackson's ObjectMapper, and how do you change a setting like the naming strategy?
ConceptFoundations6 min read
Is ObjectMapper thread-safe? How should it be used in a service?
ScenarioIntermediate7 min read
Spring Boot 4 moves to Jackson 3. What changes would you check when upgrading a service?
DesignAdvanced7 min read
Design a shared Jackson configuration for all services and explain how teams can extend it without replacing Boot's ObjectMapper.
LeadershipPrincipal6 min read
The move to Jackson 3 in Spring Boot 4 touches every service. How would you plan and sequence this change across a large fleet?

Custom serializers and deserializers

CodingFoundations7 min read
Write a custom serializer that writes a Money(amount, currency) object as "12.50 EUR" and register it.
ConceptIntermediate6 min read
When would you use @JsonCreator, @JsonValue and mix-ins instead of a custom serializer?
LeadershipPrincipal6 min read
Jackson has been the default JSON library in Spring for over a decade and now has a major version change. How should an organisation think about dependence on such foundational libraries?

Date and time handling

DebuggingFoundations6 min read
A LocalDateTime field is returned as an array like [2024,5,1,10,30] in one service and as a string in another. Why?
CodingIntermediate6 min read
A client sends dates as dd.MM.yyyy. Show how to accept this for one field and when you should avoid doing it.
DesignIntermediate7 min read
Which Java type would you use for timestamps in an API: LocalDateTime, OffsetDateTime or Instant? Explain the JSON format.
ScenarioAdvanced7 min read
Mobile clients in different time zones see wrong dates because services use LocalDateTime and different formats. How would you fix this across 30 services?

Polymorphic types

CodingFoundations7 min read
Deserialize a list of payment methods where each JSON object has a type field (card or bank) into the correct subclass.
ConceptIntermediate7 min read
Why is using JsonTypeInfo.Id.CLASS or enabling default typing dangerous on data from clients?
DesignAdvanced7 min read
Events between services use polymorphic JSON with type information. How would you design this so producers and consumers can evolve independently?

Unknown properties

ConceptFoundations6 min read
What happens when a JSON request contains a field that the target class does not have, in plain Jackson and in Spring Boot?
DesignIntermediate7 min read
Should your API reject unknown fields in requests or ignore them? Discuss for public APIs and for internal events.
LeadershipPrincipal6 min read
Some teams want to replace JSON with Protobuf or Avro for internal traffic. How would you decide on wire formats for the company over the next decade?

Jackson performance and security

ConceptIntermediate7 min read
Which Jackson protections exist against malicious JSON such as deeply nested arrays or very long numbers?
ScenarioIntermediate7 min read
A JSON endpoint is slow and uses a lot of memory for large responses of 100,000 rows. How would you improve it?
LeadershipAdvanced6 min read
How would you set standards for JSON serialization across your services, so that the same types look the same everywhere?
LeadershipPrincipal6 min read
Jackson has had many security advisories over the years, mostly around polymorphic deserialization. What does this history teach about long-term security posture for serialization libraries?

XML with Jackson

CodingFoundations6 min read
Using Jackson's XmlMapper (jackson-dataformat-xml), map a Book class so that id is an XML attribute and authors is written as <authors><author>..</author></authors>. Then show the code to read and write.
DebuggingIntermediate7 min read
After a dependency upgrade added jackson-dataformat-xml to the classpath, a Spring MVC JSON API started returning XML to some clients, including browsers. Explain and fix.
DesignAdvanced6 min read
An API must offer JSON and XML representations to partners. Would you use Jackson for both, or JAXB for XML and Jackson for JSON? Discuss for a long-lived public API.

Jackson 3 migration

ConceptFoundations6 min read
What are the most visible changes developers meet when moving code from Jackson 2 to Jackson 3?
ScenarioIntermediate6 min read
Your Spring Boot 3 service has custom serializers, mix-ins and a Jackson2ObjectMapperBuilderCustomizer. Plan the upgrade to Spring Boot 4 with Jackson 3.
DesignAdvanced6 min read
Shared libraries in your company expose Jackson 2 types (ObjectMapper parameters, JsonNode return values) in their public APIs. How do you manage the Jackson 3 transition across 120 services?

Tree model and map conversion

CodingFoundations6 min read
Convert a Map<String, Object> received from a message queue into a typed Customer object and back, without writing JSON strings in between.
CodingFoundations6 min read
Read this JSON with Jackson's tree model and print the email of the second user, safely handling missing fields: {"users": [{"email": "a@x.com"}, {"name": "b"}]}
DesignIntermediate7 min read
A gateway service must forward JSON payloads while changing only two fields. Would you bind to POJOs, use the tree model, or use streaming? Discuss memory, correctness and schema evolution.

Creators and constructor binding

CodingFoundations6 min read
Deserialize {"id": 7, "name": "Ann"} into an immutable class with final fields and no setters, and into a Java record. What is needed in each case?
DebuggingIntermediate6 min read
A class has two constructors, and Jackson fails with 'Cannot construct instance of Price (no Creators, like default constructor, exist): cannot deserialize from Number value'. The JSON is just 12.5. Explain and fix.
DesignAdvanced6 min read
Teams write API DTOs as mutable beans, Lombok builders, and records in the same code base, and deserialization bugs keep appearing. What standard would you set?

Generic collections with TypeReference

DebuggingFoundations6 min read
This code throws ClassCastException: java.util.LinkedHashMap cannot be cast to Order:
List<Order> orders = mapper.readValue(json, List.class);
orders.get(0).getId()
Explain and fix.
CodingIntermediate5 min read
Write a generic method <T> Page<T> readPage(String json, Class<T> itemType) that deserializes {"items": [...], "total": 3} into Page<T>. Why does a TypeReference not work here?
ScenarioAdvanced7 min read
A shared event library deserializes Envelope<T> payloads with generic types, and consumers often get maps instead of their types. How would you redesign the library API?