[Simple-support] Streaming root elements
Brought to you by:
niallg
|
From: Niklas H. <nik...@ni...> - 2009-05-26 12:59:34
|
Hi,
I'm new at this - and I'm probably doin' some trivial error.
I have a very simple implementation and I like to put some Simple-java
classes on a stream, in sequence.
In the below example the XML is put on a stream and I would have hoped that
the persister should manage to parse the stream as several sequential XML
root nodes (i.e. AnnotatedTestClass instances)
But the first invocation of persister.read(clazz, inputStream) empties the
stream but however just one object is returned.
The next attempt to invoke the method will block, naturally.
How do I get around this? Is it possible or have I misunderstood the usage
of stream as input?
Many thanks in advance
- Niklas
// XML is
"<annotatedTestClass>
<num>77</num>
<name>test1</name>
</annotatedTestClass><annotatedTestClass>
<num>77</num>
<name>test1</name>
</annotatedTestClass><annotatedTestClass>
<num>77</num>
<name>test1</name>
</annotatedTestClass>"
// Sample code
persister = new org.simpleframework.xml.core.Persister();
for (int iter=0; iter<3; iter++) {
AnnotatedTestClass obj2 =
(AnnotatedTestClass)persister.read(AnnotatedTestClass.class, inputStream);
// etc ...
}
// Class impl
@Root(strict=false)
public class AnnotatedTestClass {
public AnnotatedTestClass() {
}
@Element(required=false)
private Integer num;
@Element(required=false)
private String name;
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object obj) {
AnnotatedTestClass other = (AnnotatedTestClass)obj;
boolean eq = Equals.equals(this.num, other.getNum());
eq &= Equals.equals(this.name, other.getName());
return eq;
}
|