Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

After moving a service from WildFly to a Jersey-based runtime, dates in responses changed from "2026-03-01T10:00:00Z" to arrays like [2026,3,1,10,0], and unknown request fields now cause 400 errors. What happened and how do you fix it in one place?

The JSON provider changed. WildFly served the DTOs through JSON-B (Yasson), which writes java.time values as ISO strings and ignores unknown properties, while the Jersey setup uses Jackson, which writes java.time values as arrays or numbers while WRITE_DATES_AS_TIMESTAMPS is on (and needs the jackson-datatype-jsr310 JavaTimeModule at all) and rejects unknown properties because FAIL_ON_UNKNOWN_PROPERTIES defaults to true. We fix it in one place with a ContextResolver<ObjectMapper> registered as a @Provider, pin the provider explicitly in the ResourceConfig, and add contract tests that compare serialised DTOs with stored JSON.

Why this question is asked

A runtime migration is supposed to be invisible to clients, so a change in the JSON format is a breaking change even if every Java test passes. This kind of issue reaches production often because nobody wrote a test for the exact JSON shape. Interviewers ask it to see whether we can recognise a provider change from its symptoms and fix it centrally rather than annotating hundreds of DTO fields. In this answer, we will recap where JSON comes from in JAX-RS, see why both symptoms point to one cause, reproduce them, fix them in one provider, pin the provider so it cannot change silently again, and protect the contract with tests.

1A Quick Recap: Who Writes the JSON

In JAX-RS, JSON is written and read by entity providers, MessageBodyWriter and MessageBodyReader implementations supplied by a JSON library. On WildFly, the default JSON binding is JSON-B, the Jakarta standard, implemented by Yasson (WildFly also offers Jackson through RESTEasy, depending on configuration). On a standalone Jersey runtime, it is whichever media module is on the classpath, and jersey-media-json-jackson is a very common choice.

JSON-B and Jackson are both good libraries, but they have different defaults. So when the runtime changed, the code and the DTOs stayed the same, but the library that turns them into JSON did not. Both symptoms, the date format and the strict handling of unknown fields, are default differences between the two libraries, which is the clue that this is one problem, not two.

2Reproducing Both Symptoms

Take a DTO with a LocalDateTime field and a client that sends an extra field the service does not know.

Java
public record OrderDto(long id, LocalDateTime createdAt) {}
// WildFly with JSON-B (Yasson)
// {"createdAt":"2026-03-01T10:00:00","id":42}
// Jersey with Jackson, JavaTimeModule registered, default features
// {"id":42,"createdAt":[2026,3,1,10,0]}
// Instant or OffsetDateTime fields would become numbers such as 1772359200.000000000
// Request body with a field the DTO does not have
// {"id":42,"createdAt":"2026-03-01T10:00:00","channel":"web"}
// JSON-B: field ignored, 200
// Jackson: UnrecognizedPropertyException: Unrecognized field "channel" -> mapped to 400
Default behaviour of the two providers
BehaviourJSON-B (Yasson)Jackson 2 defaults
LocalDateTime"2026-03-01T10:00:00"[2026,3,1,10,0] with JavaTimeModule
InstantISO string with ZNumber of epoch seconds
java.time without extra moduleSupportedFails: needs jackson-datatype-jsr310
Unknown input propertyIgnoredFails, request becomes 400
Property orderAlphabetical by defaultDeclaration order

Notice what each library is doing. Jackson's SerializationFeature.WRITE_DATES_AS_TIMESTAMPS is enabled by default in Jackson 2, so java.time values are written in a numeric form: an array of fields for LocalDate and LocalDateTime, and seconds since the epoch for Instant. Without the jackson-datatype-jsr310 JavaTimeModule, Jackson 2 cannot handle java.time types at all and fails with an error instead. And DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES defaults to true, so an unknown field fails the whole request, while JSON-B ignores unknown properties by default. Jackson 3 changes several of these defaults, so check your version.

3Fixing It Once With a ContextResolver

We do not want to put @JsonFormat on every date field in every DTO. Jackson's JAX-RS provider asks for a ContextResolver<ObjectMapper> before it serialises anything, so if we register one, every resource uses our configured mapper.

Java
@Provider
public class JsonConfig implements ContextResolver<ObjectMapper> {
private final ObjectMapper mapper = JsonMapper.builder()
.addModule(new JavaTimeModule()) // java.time support
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) // ISO-8601 strings
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) // tolerate extra fields
.build();
@Override
public ObjectMapper getContext(Class<?> type) { return mapper; } // one shared, thread-safe mapper
}
// {"id":42,"createdAt":"2026-03-01T10:00:00"}
// unknown "channel" field -> ignored, 200

If we decided to stay on JSON-B instead, the same idea works with a ContextResolver<Jsonb> that returns JsonbBuilder.create(new JsonbConfig()...) with our settings. The point is that the format is configured in one provider, so it is the same for all endpoints.

4Pinning the Provider So It Cannot Change Silently

The root cause was not Jackson; it was that the JSON library was chosen implicitly by whatever was on the classpath. Jersey auto-discovers media modules, so adding a library that happens to bring in another JSON module can change the output again. We make the choice explicit in the application configuration.

Java
public class ShopApplication extends ResourceConfig {
public ShopApplication() {
packages("com.example.shop.api");
register(JacksonFeature.class); // the JSON provider we chose
register(JsonConfig.class); // its configuration
// Optionally stop auto-discovered features from adding another JSON provider:
// property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true); check your version's options
}
}

We also remove the JSON module we do not use from the dependency tree, so only one JSON provider is present at all.

5Catching Provider Changes in CI

Finally, we add contract tests that serialise representative DTOs through the real runtime configuration and compare the result with stored JSON files, often called golden files. A test can start the resources in memory, call GET /orders/42 and compare the body with orders-42.json, ignoring field order where that does not matter. Another test posts a body with an unknown field and expects 200.

So the next time a dependency upgrade or a runtime move changes a date format, the build fails with a clear diff instead of a client discovering it in production.

6Follow-up questions

How does provider priority work when two writers match?

When two JSON writers both accept the type and media type, the runtime sorts them by how closely their declared media type and Java type match, then prefers application-supplied providers over built-in ones, and newer Jakarta REST versions also consider @Priority. Two general-purpose JSON providers usually tie on everything that matters, so the winner can depend on registration order and the version; that is why we register one explicitly and remove the other.

Should we tolerate unknown fields on input?

For most public APIs, yes: the tolerant reader approach lets clients and servers evolve independently. If a team wants strictness to catch typos, it should be a deliberate, documented decision applied consistently, not a side effect of a library default.

Is LocalDateTime the right type for timestamps on the wire?

Usually not. It has no offset, so clients cannot tell which time zone it means. Instant or OffsetDateTime, written as ISO 8601 with Z or an offset, is safer for APIs.

7Conclusion

In this answer, we saw that both symptoms come from one change: the JSON provider moved from JSON-B to Jackson, whose defaults write java.time as arrays or numbers and fail on unknown properties. A single ContextResolver<ObjectMapper> registered as a @Provider restores ISO dates and tolerant input for every endpoint, explicit registration in the ResourceConfig keeps the classpath from choosing the provider again, and golden-file contract tests make any future change visible in CI.

What to say in the interviewAbout 80 seconds aloud

Open with

Both symptoms point to one cause: the JSON provider changed. On WildFly the DTOs went through JSON-B with Yasson, which writes java.time values as ISO strings and ignores unknown properties.

Then, if they want more

The Jersey runtime is using Jackson, and Jackson 2's defaults are different. WRITE_DATES_AS_TIMESTAMPS is on, so with the JavaTimeModule a LocalDateTime is written as an array like 2026, 3, 1, 10, 0, and an Instant as epoch seconds; without the jsr310 module it cannot handle java.time at all.

And FAIL_ON_UNKNOWN_PROPERTIES defaults to true, so an extra field in a request causes an exception that becomes a 400. I would fix it in one place rather than on every DTO: a ContextResolver of ObjectMapper annotated @Provider, returning one shared mapper with the JavaTimeModule, WRITE_DATES_AS_TIMESTAMPS disabled and FAIL_ON_UNKNOWN_PROPERTIES disabled.

If we preferred to stay on JSON-B, a ContextResolver of Jsonb with a JsonbConfig does the same. Then I would pin the provider: register JacksonFeature and the resolver explicitly in the ResourceConfig and remove the other JSON module, because Jersey auto-discovers media modules and the classpath should not decide our wire format.

Finally I would add contract tests that serialise representative DTOs through the real configuration and compare them with stored JSON, so a provider change fails the build instead of breaking clients.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Jakarta EE specifications
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "After moving a service from WildFly to a Jersey-based runtime, dates in responses...": https://scrivio-interview-library.netlify.app/java/jax-rs/5c34d34811/