Marshal object iterator using JAXB

I have a problem marshaling an object iterator using JAXB

User class:

public class User{
    private Long id;
    private String name,mailid;
    private boolean isActive;
    public Long getId() {

        return id;
    public void setId(Long id) { = id;
    public String getName() {
        return name;
    public void setName(String name) { = name;
    public String getMailid() {
        return mailid;
    public void setMailid(String mailid) {
        this.mailid = mailid;
    public boolean isActive() {
        return isActive;
    public void setActive(boolean isActive) {
        this.isActive = isActive;



Function that returns a User Iterator :

public static Iterator<User> mapDoToUserObject(DataObject dao){

    final Iterator<Row> userRow = getRow(dao,USER.TABLE);

    return new Iterator<User>() {
        public boolean hasNext() {
            return userRow.hasNext();

        public User next() {
            Row user =;
            User user = new User();
            user.setName((String) user.get(USER.FIRST_NAME));
            return user;

        public void remove() {
            throw new UnsupportedOperationException("Remove not supported");



How do I set up a users iterator using JAXB?


source to share

1 answer

You will need to merge the iterator into a collection and then marshal that (this is the simplest solution), or use JAXB's incremental sort feature, which means iterating over the iterator yourself and sorting the individual objects. For a description of how to do this, see Can JAXB increment an object marker?



All Articles