Scrivio Interview library

JAXB XML binding

25 questions in 8 subtopics.

Marshalling and unmarshalling

CodingFoundations7 min read
Using Jakarta XML Binding (jakarta.xml.bind), write code that turns an Order object into an XML string and back. Which dependencies does a Java 25 project need, and what happened to javax.xml.bind?
DebuggingFoundations7 min read
A service creates JAXBContext.newInstance(Invoice.class) inside a method called for each request. Under load CPU is high and heap shows many com.sun.xml.bind classes. What is wrong and how do you fix it?
ScenarioIntermediate7 min read
You must import a 6 GB XML file of 10 million <customer> elements with JAXB. Unmarshalling the whole document runs out of memory. How would you process it?
LeadershipPrincipal6 min read
JAXB was part of the JDK, was removed in Java 11, and now lives on as Jakarta XML Binding. What does this history teach about depending on platform-bundled libraries, and how would you decide whether to keep investing in XML binding at all?

JAXB annotations

ConceptFoundations6 min read
Explain @XmlRootElement, @XmlElement, @XmlAttribute, @XmlTransient and @XmlAccessorType, using a Product class with id as an attribute and name as an element.
DesignIntermediate7 min read
You must produce XML for a partner whose schema uses namespaces, a fixed element order and optional elements. Which JAXB annotations control this, and how do you keep your domain model clean?
ScenarioAdvanced7 min read
Forty services exchange XML with banks and government systems through JAXB models, half still on javax.xml.bind. Plan the migration to Jakarta XML Binding.

Root elements and JAXBElement

DebuggingFoundations7 min read
Unmarshalling fails with: 'jakarta.xml.bind.UnmarshalException: unexpected element (uri:"http://acme.com/order", local:"order"). Expected elements are <{}order>'. What does this mean?
ConceptIntermediate6 min read
When does xjc generate classes without @XmlRootElement, and how do you marshal and unmarshal such types using JAXBElement?

XmlAdapter

CodingFoundations6 min read
Write an XmlAdapter so that a java.time.LocalDate field is written as 2026-11-04 and read back, and show how it is applied.
DesignIntermediate6 min read
Your XML contract represents money as <amount currency="EUR">12.50</amount>, but your domain uses an immutable Money record without a no-argument constructor. How would you map it with JAXB?
DesignPrincipal7 min read
Integration code across your company converts the same partner XML into domain objects in many different ways, with adapters copied between services. How would you organise mapping code at company scale?

Binding collections and maps

CodingFoundations6 min read
Map a class Order with a List<Line> lines so that the XML looks like <order><lines><line>...</line><line>...</line></lines></order>. What changes if you drop the wrapper element?
CodingIntermediate6 min read
JAXB cannot map Map<String, Integer> to <stock><item sku="A1" qty="5"/></stock> directly. Write the adapter approach.
ScenarioAdvanced7 min read
Partner XML files contain lists with 500,000 elements, and services map them into in-memory Lists via JAXB. Memory incidents follow. What would you change in design and standards?

XSD generation and validation

CodingFoundations7 min read
Validate incoming XML against an order.xsd while unmarshalling with JAXB, and collect all errors instead of failing on the first.
DesignIntermediate7 min read
A partner publishes an XSD that changes twice a year. Would you generate classes with xjc (contract first) or annotate Java classes and generate the XSD (code first)? How would you build it?
DesignAdvanced7 min read
Design how XML contracts with 30 external partners are governed: schema storage, versioning, generated code and testing.
LeadershipPrincipal6 min read
Your company runs 40 services with JAXB-based integrations, some generated from XSDs nobody owns. How do you decide when to retire JAXB and the XML contracts behind it?

MOXy JSON binding

CodingFoundations7 min read
Using MOXy, how would you map a JSON property address.city into a flat field city on a Customer class, and what properties make the JSON output omit the root element?
ConceptIntermediate7 min read
What is EclipseLink MOXy, and why would a team use it to produce JSON from JAXB-annotated classes instead of Jackson?
DesignAdvanced6 min read
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?

Common JAXB errors

DebuggingFoundations6 min read
Explain each JAXB error and its fix: (a) 'IllegalAnnotationsException: Class has two properties of the same name "id"', (b) 'Implementation of JAXB-API has not been found on module path or classpath', (c) 'does not have a no-arg default constructor'.
DebuggingIntermediate7 min read
After migrating to Spring Boot 3 and Jakarta, a SOAP client fails at startup with ClassNotFoundException: javax.xml.bind.JAXBElement, coming from a third-party library. How do you resolve it?
ScenarioAdvanced7 min read
A security scan shows that several services parse XML from partners with default parser settings. Explain the risk with JAXB and how to fix it across the company.