Skip to content
Example demonstrating how EclipseLink JAXB (MOXy) can map a field/property to an element based on the value of one of its attributes.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src/main Removed unnecessary whitespace. Jan 11, 2012

Map to Element based on an Attribute Value with EclipseLink JAXB (MOXy)

This is the complete source code for the following blog post:


In EclipseLink 2.3 the @XmlPath annotation was enhanced to support predicates. This allows us to map the class below:

public class Customer {

    private String name;

    private Address address;

    private List<PhoneNumber> phoneNumbers;


To the following XML:

<?xml version="1.0" encoding="UTF-8"?>
    <node name="name">Jane Doe</node>
    <node name="address">
        <node name="street">123 A Street</node>
    <node name="phone-number" type="work">555-1111</node>
    <node name="phone-number" type="cell">555-2222</node>

Compile the Example

You can compile the example code using the following command. Maven will automatically fetch the required dependencies.

 mvn compile

Run the Example

You can run the example using the following command.

mvn exec:java
Something went wrong with that request. Please try again.