2012-03-08 79 views
3

我具有編組使用JAXB元帥使用JAXB

一個對象的迭代問題對象的一個​​迭代

用戶類:

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

     return id; 
    } 
    public void setId(Long id) { 
     this.id = id; 
    } 
    public String getName() { 
     return name; 
    } 
    public void setName(String name) { 
     this.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; 
    } 

} 

該函數返回的用戶的Iterator:

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

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


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

     @Override 
     public User next() { 
      Row user = userRow.next(); 
      User user = new User(); 
      user.setId((Long)user.get(USER.USER_ID)); 
      user.setName((String) user.get(USER.FIRST_NAME)); 
      user.setMailid((String)user.get(USER.EMAIL_ID)); 
      return user; 
     } 

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

     } 
    }; 
} 

如何編組用戶使用JAXB的迭代器?

回答

4

您將需要將迭代器抽取到集合中,然後封送(這是最簡單的解決方案),或者使用JAXB的增量編組功能,這意味着您自己迭代迭代器並編組單個對象。有關如何操作的說明,請參閱Can JAXB Incrementally Marshall An Object?