Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Java has seen many JSON libraries (Jackson, Gson, JSON-B, JSON-P, org.json) and several serious deserialization vulnerabilities. What long-term policy would you set for JSON libraries across a large company?

I would limit the approved JSON libraries to one or two, each with a named owning team, and pin their versions through a platform BOM. I would ban polymorphic type handling driven by untrusted input, such as Jackson's default typing, and require explicit allow-lists where polymorphism is needed, and I would require fast patching with dependency scanning and an SLA for critical CVEs. The wire format stays a contract owned by the APIs, so the library can change without clients noticing, and the policy is reviewed as standards and major versions change, for example Jakarta JSON-B releases and Jackson 3.

Why this question is asked

JSON parsing sits on the edge of almost every service, reading data that comes from outside, so a weakness in a JSON library is a weakness in every application that uses it. Java has had several serious deserialization vulnerabilities, many of them in JSON libraries configured to create arbitrary classes from input. At the same time, large companies end up with five JSON libraries because every team picked its favourite. Interviewers ask this to see whether we can set a policy that reduces risk and cost without blocking teams. In this answer, we will see why deserialization is dangerous, choose the approved set, write the safety rules, make patching fast, separate the wire format from the library and plan how the policy evolves.

1Why JSON Deserialization Is a Security Topic

Deserialization means turning bytes from outside into objects in our program. That is safe as long as the input decides only the data, such as field values. It becomes dangerous when the input can decide which class gets created. Jackson's default typing, for example, writes and reads a class name in the JSON, so an attacker who controls the input can name any class on the classpath. Some classes, called gadgets, do something harmful when they are created or their setters are called, such as opening a JNDI connection or running a command.

Between roughly 2017 and 2020, jackson-databind received a long series of CVEs, each adding gadget classes to a block list, because applications with default typing enabled were exploitable through whatever libraries happened to be on their classpath. Jackson 2.10 introduced PolymorphicTypeValidator so that polymorphism could be restricted to an allow-list. The lesson is that the risk comes mostly from configuration, so a policy has to cover how libraries are used, not only which ones.

2Limiting the Approved Set

Every library we allow costs something: someone has to track its releases, patch it, answer questions and keep configuration consistent. So I would approve a small set, for example Jackson as the default for Spring and standalone services and JSON-B for teams on Jakarta EE runtimes where the platform provides it, with JSON-P allowed for low-level streaming. Gson and org.json would be allowed only in existing code, with no new use, because they duplicate what the approved libraries do.

Each approved library gets a named owning team, usually the platform team, and versions are pinned through a company BOM, a bill of materials that fixes the version of every related artifact, such as all Jackson modules, so services cannot drift onto mixed versions.

An example approved set
LibraryStatusWhereOwner
Jackson (2.x, then 3.x)DefaultSpring Boot and standalone servicesPlatform team
JSON-B (Yasson)ApprovedJakarta EE runtimesPlatform team
JSON-PApprovedLow-level streaming and patchingPlatform team
GsonExisting code onlyNo new use; migrate on changeOwning service team
org.jsonExisting code onlyNo new use; migrate on changeOwning service team

3Rules for Safe Use

The most important rule is that polymorphic type handling must never be driven by untrusted input in an unrestricted way. That means no activateDefaultTyping or the older enableDefaultTyping on mappers that read external data, and no @JsonTypeInfo(use = Id.CLASS) on types that come from requests or messages. Where polymorphism is genuinely needed, for example an event that can be one of several types, we use logical names with an explicit list of subtypes, or a PolymorphicTypeValidator that allows only our own packages.

Java
// Banned on input from outside: the JSON chooses the class
mapper.activateDefaultTyping(mapper.getPolymorphicTypeValidator()); // any class on the classpath
// Allowed: logical names, a closed set of subtypes
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = OrderPlaced.class, name = "order-placed"),
@JsonSubTypes.Type(value = OrderCancelled.class, name = "order-cancelled")
})
public sealed interface OrderEvent permits OrderPlaced, OrderCancelled {}
// {"type":"order-placed",...} -> OrderPlaced; any other type -> error

We enforce this with tooling rather than trust: an ArchUnit test or a static analysis rule in the build flags calls to the default typing methods and Id.CLASS annotations, and the shared mapper configuration from the platform team is safe by default. The same thinking applies to Java's own serialization, which should not read untrusted data at all.

4Making Patching Fast

No policy prevents every vulnerability, so the real measure is how fast we patch. Dependency scanning runs on every build and on deployed images, using tools such as OWASP Dependency-Check, Dependabot, Renovate or a commercial scanner, and SBOMs record exactly which versions each service runs. Then an SLA sets the expectation, for example critical CVEs in internet-facing services patched within 7 days and high ones within 30.

The BOM makes this practical. When a new Jackson patch release fixes a CVE, the platform team updates one version in the BOM, and services pick it up with their next dependency update, often opened automatically as a pull request. So a fix reaches 200 services in days, not months.

Step throughFrom CVE to patched services
  1. CVE published for a JSON libraryScanner flags affected builds
  2. Platform team updates the BOMOne version change
  3. Bots open update pull requestsIn every affected service
  4. Tests pass, services deployWithin the SLA
  5. Dashboard shows remaining servicesEscalate those past the SLA

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

5Keeping the Wire Format Independent of the Library

The JSON that clients see should be a contract owned by each API and described in its OpenAPI specification, with company rules for dates, nulls, enums and money. Contract tests with golden files check that a service produces exactly that JSON. Because the tests check the output rather than the library, we can move a service from Gson to Jackson, or from Jackson 2 to Jackson 3, and know that clients see no change.

This is what makes the policy sustainable over ten years. Libraries come and go, but if the wire format is pinned by tests, a library change is an internal refactoring rather than a breaking change.

6Reviewing the Policy as Standards Change

The landscape moves. Jakarta JSON-B 3.0 in Jakarta EE 10 added standard polymorphism support, and Jackson 3 is a major release with new package names and changed defaults, which Spring Boot 4 adopts by default; check your version for the exact support of Jackson 2 alongside it. A major release like that needs a planned migration, guidance for teams, and an update to the BOM and the shared configuration.

So the policy has an owner and a review date, for example once a year and whenever a major version of an approved library ships. The review looks at CVE history, maintenance health of each library, and what our frameworks now default to.

7Follow-up questions

Would you ever allow a third JSON library?

Yes, with a written exception, if a team has a real need such as a very high-performance parser for a specific workload. The exception names the owner, the version policy and an end date or review date, so it does not quietly become a permanent part of the platform.

Is banning default typing enough to be safe?

It removes the largest class of JSON deserialization attacks, but we also need limits on input size and nesting depth to prevent denial of service, safe handling of very large numbers, and patching for bugs in the parsers themselves. Recent Jackson versions add stream read constraints for exactly those limits.

How do you handle libraries that bring their own JSON dependency?

The BOM also pins transitive versions, and the scanner reports them. If a library shades an old JSON library inside its jar, we treat it like any other vulnerable component and push for an upgrade or replacement.

8Conclusion

In this answer, we saw that JSON libraries are a security concern mainly because unrestricted polymorphic deserialization lets input choose classes. A good long-term policy keeps a small approved set with named owners and versions pinned in a BOM, bans default typing on untrusted input and requires allow-lists, enforces fast patching through scanning and an SLA, keeps the wire format as a tested API contract so libraries can change, and is reviewed as JSON-B, Jackson 3 and other standards evolve.

What to say in the interviewAbout 90 seconds aloud

Open with

I would set the policy around two goals: fewer libraries and safe use. First, a small approved set, for example Jackson as the default and JSON-B for teams on Jakarta EE runtimes, with JSON-P for low-level work.

Then, if they want more

Gson and org.json stay only in existing code. Each approved library has a named owning team, and versions are pinned in a company BOM so all Jackson modules move together.

Second, safety rules, because most of the serious Java JSON vulnerabilities came from configuration: Jackson's default typing lets the input name any class on the classpath, and gadget classes turn that into code execution.

So default typing and Id.CLASS on untrusted input are banned, enforced by an ArchUnit or static analysis rule, and where we need polymorphism we use logical type names with an explicit subtype list or a PolymorphicTypeValidator allow-list.

Third, fast patching: dependency scanning on every build and image, SBOMs, and an SLA such as seven days for critical CVEs on internet-facing services, which the BOM makes easy because one version change flows to every service through automated pull requests.

Fourth, the wire format is a contract owned by each API and checked by golden-file tests, so we can change libraries, for example from Jackson 2 to Jackson 3, without clients noticing. And the policy gets reviewed yearly and at major releases.

About this answer

Last updated
12 November 2026
Versions it names
Jakarta EE 10, Spring Boot 4
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 "Java has seen many JSON libraries (Jackson, Gson, JSON-B, JSON-P, org.json) and several...": https://scrivio-interview-library.netlify.app/java/jax-rs/91a988ac9e/