Q:

Java: XML to Object and Object to XML with properties

I have a not-little problem with my current project, and probably you can help me with this...
When I worked before with xml messages, marshalling converted java objects to xml, where the java object attributes were set to xml nodes. But now I need to set that object attributes to xml node attributes, as I show here:
<Identification_List counter="">
   <Identification number="XXXXXXX" letter="X" name="PERSON">
      <TravelList counter="">
          <Travel travelType="">
      </TravelList>
   </Identification>
</Identification_List>

How can I do this? What framework should I use? Thank you!
Edit: Example java class:
public class Identification {
  private int number;
  private char letter;
  private String name;
  private List<Travel> travelList;

  //Add here constructors, getters and setters
}

That java class is the one that should be marshalled, where number, letter and name are the xml object properties

A:

You need to add the appropriate JAXB annotations to your classes, to tell JAXB how to map your class to XML. For example:
@XmlRootElement(name = "Identification_List")
@XmlAccessorType(XmlAccessType.FIELD)
public class IdentificationList {

    @XmlAttribute
    private int counter;

    @XmlElement(name = "Identification")
    private List<Identification> identifications;

    // getters and setters
}

@XmlAccessorType(XmlAccessType.FIELD)
public class Identification {

    @XmlAttribute
    private int number;

    @XmlAttribute
    private char letter;

    @XmlAttribute
    private String name;

    @XmlElementWrapper(name = "TravelList")
    @XmlElement(name = "Travel")
    private List<Travel> travels;

    // getters and setters
}

@XmlAccessorType(XmlAccessType.FIELD)
public class Travel {

    @XmlAttribute
    private String travelType;

    // getters and setters
}

