[英]Marshal an iterator of object using JAXB
I having problem marshaling an iterator of objects using JAXB 我有问题使用JAXB封送对象的迭代器
User class: 用户类:
@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;
}
}
Function which return's an Iterator of User : 返回用户的迭代器的函数 :
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");
}
};
}
How to marshal an iterator of Users using JAXB ? 如何使用JAXB编组用户的迭代器?
You'll either need to drain the iterator into a collection and then marshal that (which is the easiest solution), or else use JAXB's incremental marshalling feature, which means iterating over the iterator yourself and marshalling the individual objects. 您需要将迭代器排入集合,然后编组(这是最简单的解决方案),或者使用JAXB的增量编组功能,这意味着自己迭代迭代器并编组各个对象。 For a description on how to do that, see Can JAXB Incrementally Marshall An Object? 有关如何执行此操作的说明,请参阅JAXB可以增量Marshall一个对象吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.