Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

A Jakarta EE application uses MOXy for JSON while new Spring Boot services use Jackson, and clients see different JSON for the same types. How would you converge?

We converge by making the JSON contract itself, written as OpenAPI or JSON Schema, the source of truth, and then measuring how MOXy and Jackson each differ from it in nulls, dates, numbers, empty lists and root wrappers. We then choose one binder per platform direction, usually Jackson for Spring services, guard the shared types with contract tests that compare serialized output, and move clients onto any visible change through a versioned API.

Why this question is asked

When two stacks serialize the same business types, clients notice the differences first. A mobile team finds that an Order from one endpoint has "discount":null while the same Order from another endpoint has no discount key at all, or that dates arrive once as an ISO string and once as a number. Each difference is small, but together they force clients to write defensive code and they make bugs hard to trace. Interviewers ask this design question to see whether we fix the cause, which is a missing contract, rather than only patching the symptom. In this answer, we will see why the outputs differ, define the contract, compare the binders field by field, pick a direction for each platform, add contract tests, and plan the migration so no client breaks.

1Why the Same Type Comes Out Differently

MOXy and Jackson start from different ideas. MOXy is an XML binder that also writes JSON, so it reads JAXB annotations and keeps XML habits: a root element wrapper unless we turn it off, attributes turned into keys, and nulls left out unless an element is marked nillable. Jackson is a JSON binder first: it discovers properties from getters and fields, writes nulls by default, and follows the settings of the ObjectMapper, which Spring Boot adjusts, for example by writing dates as ISO strings instead of numbers.

Neither output is wrong. The problem is that nobody wrote down which one is right, so each platform's defaults became the contract by accident. That is the first thing to fix.

2Make the Contract the Source of Truth

We write the JSON contract for the shared types explicitly, in an OpenAPI document for the HTTP APIs or a JSON Schema for messages. The contract answers each question that the binders answer differently: is an absent value omitted or written as null, are dates ISO-8601 strings with an offset, are money amounts strings or numbers, is an empty list written as [] or omitted, and is there a root wrapper.

YAML
Order:
type: object
required: [id, createdAt, lines]
properties:
id: { type: integer }
createdAt: { type: string, format: date-time } # "2026-11-05T10:15:30Z"
total: { type: string, example: "12.50" } # decimal as string, never 1.25E1
discount: { type: string, nullable: true } # omitted when absent
lines: { type: array, items: { $ref: "#/components/schemas/Line" } } # [] when empty

Once this exists, the question stops being "MOXy or Jackson" and becomes "does each service meet the contract". That shifts the argument from taste to evidence.

3Compare the Outputs Field by Field

Next we serialize a set of representative objects through both stacks and diff the results. The table in this section shows the kind of differences that usually appear. The exact behaviour depends on versions and settings, so we always measure our own services rather than trusting a general list.

Typical differences for the same Order
AspectMOXy (common default)Jackson (Spring Boot default)
Root wrapper{"order":{...}} unless JSON_INCLUDE_ROOT is falseNo wrapper
Null fieldOmitted unless nillableWritten as null
DatesXML Schema dateTime stringISO-8601 string (Boot disables timestamps)
BigDecimalPlain numberNumber, may use exponent unless configured
Empty listMay be omitted, depends on settingsWritten as []
NamesFrom @XmlElementFrom getters, or @JsonProperty
Measure your own versions: these are the places to look, not guaranteed values.

Each row becomes a configuration decision. On the Jackson side we can set the inclusion rule to NON_NULL, disable timestamps for dates, and write BigDecimal as plain strings. On the MOXy side we can turn off JSON_INCLUDE_ROOT and adjust nillable and collection settings. Often most differences disappear with configuration alone, before any code moves.

4Choose One Binder per Platform Direction

Running two binders forever means two sets of defaults to keep aligned. So we choose a direction. For the Spring Boot services, Jackson is the obvious choice: it is already configured for HTTP, and fighting it costs more than it saves. For the Jakarta EE application we have two reasonable paths. If it will stay on Jakarta EE, many runtimes provide JSON-B (Jakarta JSON Binding, with Yasson as the usual implementation) or allow Jackson as the JSON provider, and either can be configured to the contract. If the application is going to be rebuilt on Spring, we leave MOXy configured to the contract and replace it at that point.

The cost to weigh is client impact. Switching binders silently changes output in places nobody tested, so the switch is only safe once the contract tests from the next step exist.

5Contract Tests for Shared Types

A contract test serializes a known object and compares it with an approved JSON sample, and validates it against the schema. We run the same samples in both codebases, so both binders are held to one standard.

Java
@Test
void orderMatchesContract() throws Exception {
Order order = Fixtures.order(7, "2026-11-05T10:15:30Z", List.of());
String json = mapper.writeValueAsString(order);
JSONAssert.assertEquals(read("contract/order-7.json"), json, JSONCompareMode.STRICT);
// passes only if field names, nulls, dates and empty lists all match the approved sample
schemaValidator.validate("Order", json); // fails on a missing required field
}

Notice that the approved sample, not the Java class, is the thing under test. A future upgrade of either library that changes the output now breaks a build instead of a client.

6Migrate Behind Versioned APIs When Clients See a Change

Some differences cannot be fixed without a visible change, for example when the Jakarta EE application has always written the root wrapper and old clients depend on it. Here we do not change the existing endpoint. We publish the contract-conforming shape as a new version, such as /v2/orders or a new media type, keep v1 unchanged, measure who still calls v1, and retire it on an announced date.

So the full path is: write the contract, diff both outputs, close differences by configuration, choose the long-term binder, protect the result with tests, and use versioning only where a client would otherwise break.

Step throughConverging two JSON stacks
  1. Write the contractOpenAPI or JSON Schema for shared types
  2. Diff MOXy and Jackson outputnulls, dates, numbers, lists, root
  3. Can configuration close the gap?
    YesConfigure both binders to the contractNoPlan a versioned endpoint
  4. Add contract tests in both codebasesapproved samples plus schema validation
  5. Choose the long-term binderJackson for Spring, JSON-B or Jackson for Jakarta EE
  6. Retire old versions on a dateafter usage drops

6 steps in order. Play them, or step through them one at a time.

7Follow-up questions

Why not simply rewrite the Jakarta EE application to use Jackson right away?

Because that changes the output for every existing client at once, in ways nobody has measured. A rewrite without a contract and tests is exactly how the inconsistency appeared in the first place. With the contract tests in place, switching becomes a safe, checkable step rather than a gamble.

What is JSON-B and how does it relate to this?

JSON-B, Jakarta JSON Binding, is the Jakarta EE standard API for mapping objects to JSON, with Yasson as the reference implementation. It has its own defaults, for example it omits nulls unless configured. It is a reasonable long-term choice for a service that stays on Jakarta EE, as long as it is configured to the same contract.

How do we stop the drift from coming back?

We keep the approved samples and the schema in a shared repository, run the contract tests in every service that produces the types, and treat a failing contract test as a breaking change that needs review. New services start from the shared mapper configuration instead of library defaults.

8Conclusion

In this answer, we saw that MOXy and Jackson disagree because each follows its own defaults when no contract exists. We converge by writing the JSON contract as the source of truth, diffing both outputs on nulls, dates, numbers, empty lists and root wrappers, closing most gaps with configuration, choosing one binder per platform, protecting the shared types with contract tests in both codebases, and moving clients to any visible change through a new API version.

What to say in the interviewAbout 80 seconds aloud

Open with

The root problem is that nobody owns the JSON contract, so each binder's defaults became the contract by accident. I would first write the contract for the shared types, as OpenAPI for the HTTP APIs or JSON Schema for messages, and decide each detail explicitly: whether absent values are omitted or null, dates as ISO-8601 strings, decimals as strings or numbers, empty lists as an empty array, and no root wrapper.

Then, if they want more

Then I would serialize representative objects through both stacks and diff them. The usual suspects are MOXy's root element wrapper, its habit of omitting nulls where Jackson writes them, date formats, BigDecimal formatting and empty collections. Most of these can be closed with configuration on both sides.

For direction, I would standardize on Jackson in the Spring services, and for the Jakarta EE application either configure MOXy to the contract until it is replaced, or move it to JSON-B or Jackson if it stays on Jakarta EE. Contract tests with approved JSON samples would run in both codebases so any drift breaks a build.

Where a client-visible change is unavoidable, I would ship it as a new API version and retire the old one once usage drops.

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 official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
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 "A Jakarta EE application uses MOXy for JSON while new Spring Boot services use Jackson...": https://scrivio-interview-library.netlify.app/java/jaxb/9f3c2a596a/