Quick revision
The short answer
EclipseLink MOXy is a JAXB (Jakarta XML Binding) implementation from the EclipseLink project that can also turn the same JAXB-annotated classes into JSON, simply by setting the media type to application/json, and it adds extensions such as @XmlPath for XPath-based mapping. Teams pick it when one set of classes must produce XML and JSON that stay consistent, typically in Jakarta EE or JAX-RS services with existing JAXB models. In a Spring Boot service, Jackson is the default for JSON, so MOXy is mostly a legacy or Jakarta EE choice.
What to remember
In this answer, we saw that MOXy is an implementation of the JAXB specification that can also marshal the same annotated classes to JSON by setting the application/json media type, usually with the root wrapper turned off. It adds @XmlPath for path-based mapping, and it becomes the provider through jaxb.properties, a system property or its own JAXBContextFactory. It makes sense when XML and JSON must stay consistent over one legacy model, while Jackson, which can read JAXB annotations through a module, remains the default and better choice in Spring Boot services.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
EclipseLink MOXy is a JAXB (Jakarta XML Binding) implementation from the EclipseLink project that can also turn the same JAXB-annotated classes into JSON, simply by setting the media type to application/json, and it adds extensions such as @XmlPath for XPath-based mapping. Teams pick it when one set of classes must produce XML and JSON that stay consistent, typically in Jakarta EE or JAX-RS services with existing JAXB models. In a Spring Boot service, Jackson is the default for JSON, so MOXy is mostly a legacy or Jakarta EE choice.
Why this question is asked
Many older enterprise systems have hundreds of classes annotated with @XmlRootElement and @XmlElement, written when SOAP and XML were the main contract. When those systems later needed a JSON API, the team had two choices: write a second set of annotations for a JSON library, or reuse the JAXB annotations they already had. Interviewers ask about MOXy to see whether we understand that JAXB is a specification with several implementations, and whether we can reason about when reusing a model is worth it. In this answer, we will recap what JAXB is, see how MOXy produces JSON from it, look at the @XmlPath extension, see how to make MOXy the JAXB provider, and then compare it with Jackson, including Jackson's own support for JAXB annotations.
1A Quick Recap of JAXB and Its Implementations
JAXB, now called Jakarta XML Binding, is a standard API for mapping Java objects to XML and back. We annotate a class, create a JAXBContext for it, and use a Marshaller to write XML or an Unmarshaller to read it. The API lives in the jakarta.xml.bind package (javax.xml.bind before Jakarta EE 9).
The important word is standard. The API jar contains only interfaces and annotations; the work is done by an implementation, also called a provider or runtime. The reference implementation is GlassFish JAXB (the jaxb-runtime artifact). EclipseLink MOXy is a second implementation of the same API. Because both implement the same specification, code that only uses jakarta.xml.bind classes runs on either one.
MOXy stands for Mapping Objects to XML, and it comes from the same project as the EclipseLink JPA provider. Beyond the specification, it adds two things that matter here: it can write and read JSON with the same mapping metadata, and it offers extra annotations in the org.eclipse.persistence.oxm.annotations package.
2Producing JSON From the Same Annotations
Here is an ordinary JAXB class. Nothing in it mentions JSON.
Notice that we changed only marshaller properties. JAXBContextFactory and MarshallerProperties here are MOXy classes from org.eclipse.persistence.jaxb. The element name full-name, the attribute id and the field access type all come from the JAXB annotations, so XML and JSON stay in step. If someone renames the element for XML, the JSON key changes with it.
There is a catch in the second output: MOXy keeps the root element as a wrapper by default, because that is what XML has. Most JSON clients do not expect that wrapper, so JSON_INCLUDE_ROOT set to false is the usual setting. The Unmarshaller accepts the same MEDIA_TYPE property, so reading JSON works the same way.
3Mapping by Path With @XmlPath
Standard JAXB maps one Java property to one XML element. Real documents are often deeper than our classes. MOXy's @XmlPath lets a flat class map into a nested structure with an XPath-like expression, so we do not need extra wrapper classes.
The same path applies to JSON, where nested elements become nested objects. This is convenient, but it is also a lock-in: @XmlPath is not part of the specification, so a class using it no longer works the same way on the reference implementation.
4Making MOXy the JAXB Provider
Code that calls JAXBContext.newInstance(Customer.class) asks the API to find an implementation. There are three common ways to make that lookup return MOXy. The first is a file named jaxb.properties in the same package as the model classes, containing one line: jakarta.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.JAXBContextFactory (with the older javax API, the key was javax.xml.bind.context.factory). The second is the same key set as a system property, which affects the whole JVM. The third, shown in the code above, is to call MOXy's JAXBContextFactory.createContext directly, which is the most explicit and needs no lookup at all.
In JAX-RS runtimes such as Jersey, MOXy can also be plugged in as the JSON message body provider (the jersey-media-moxy module), so resources that return JAXB objects are written as JSON without extra code.
| Question | MOXy | Jackson |
|---|---|---|
| Mapping source | JAXB annotations, plus MOXy extensions | Jackson annotations, getters and fields |
| Same model for XML and JSON | Yes, by design | Possible with the JAXB annotations module |
| Default in Spring Boot | No | Yes, for HTTP message conversion |
| Typical home | Jakarta EE, JAX-RS, legacy SOAP models | Spring, most new JSON services |
| Java types such as records | Limited, check your version | Well supported with modules |
5Why Not Jackson, and When Jackson Is Better
Jackson is the most widely used JSON library in Java, and Spring Boot configures it automatically for every @RestController. It reads its own annotations such as @JsonProperty, but it can also read JAXB annotations: the jackson-module-jakarta-xmlbind-annotations module provides JakartaXmlBindAnnotationModule, which, once registered on the ObjectMapper, makes Jackson honour @XmlElement names and @XmlTransient. Check your Jackson version for the exact module name, because Jackson 3 moved packages.
So the honest comparison is this. MOXy is the better choice when the XML contract is still important and the team wants a single mapping that guarantees XML and JSON match, including MOXy-specific features like @XmlPath. It is also natural in a Jakarta EE server where it is already present. Jackson is the better choice for a Spring Boot service, because it is already configured, it understands modern Java types, and the whole Spring ecosystem expects it. Using MOXy inside Spring Boot means a second JSON stack, a second set of defaults for nulls and dates, and less help from documentation and tooling.
In practice, we would keep MOXy where a stable legacy system already relies on it, and choose Jackson, possibly with the JAXB annotations module, for new services.
6Follow-up questions
Does switching JAXB provider change the XML we produce?
It can. Both providers follow the specification, but details outside it differ: namespace prefixes, the order of some elements, how empty collections and nulls are written, and error messages. So when we switch from the reference implementation to MOXy, we should compare output of real documents in tests before relying on it.
Can MOXy map classes without annotations?
Yes. MOXy supports an external XML mapping file, called an OXM or bindings file, passed when the context is created. This is useful when we cannot change the classes, for example when they come from a third-party jar, and want to keep mapping metadata out of the code.
Is MOXy still maintained?
EclipseLink, including MOXy, is still released and supports the Jakarta namespace in its 3.x and 4.x lines. It is a mature project with a smaller community than Jackson, so for new work the larger ecosystem usually decides in Jackson's favour.
7Conclusion
In this answer, we saw that MOXy is an implementation of the JAXB specification that can also marshal the same annotated classes to JSON by setting the application/json media type, usually with the root wrapper turned off. It adds @XmlPath for path-based mapping, and it becomes the provider through jaxb.properties, a system property or its own JAXBContextFactory. It makes sense when XML and JSON must stay consistent over one legacy model, while Jackson, which can read JAXB annotations through a module, remains the default and better choice in Spring Boot services.
Open with
MOXy is EclipseLink's implementation of JAXB, now Jakarta XML Binding. The interesting part is that it can marshal the same JAXB-annotated classes to JSON: I set the marshaller's media type property to application/json, usually turn off the root element wrapper, and I get JSON whose names come from the same @XmlElement and @XmlAttribute annotations.
Then, if they want more
It also adds extensions like @XmlPath, which maps a flat field to a nested path, although that ties the code to MOXy. To use it, I either put a jaxb.properties file in the model package naming MOXy's JAXBContextFactory, set the same key as a system property, or call MOXy's factory directly.
A team would choose it when it has a large existing JAXB model, often in a Jakarta EE or JAX-RS service, and needs XML and JSON to stay consistent from one mapping.
For a Spring Boot service I would normally stay with Jackson, because Boot already configures it for HTTP, it handles records and java.time well, and if I need to reuse JAXB annotations, Jackson's Jakarta XML Bind annotations module lets it read them. So MOXy is mostly a legacy or Jakarta EE choice today.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Jakarta EE 9
- 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 "What is EclipseLink MOXy, and why would a team use it to produce JSON from...": https://scrivio-interview-library.netlify.app/java/jaxb/6c572fba88/