jvYaml - round-tripping for entity/ class
Zenaan Harkness <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
Hello, I'm getting an error, and I'm stuck. Here are my three classes:
public class TestEntity {
public TestEntity () {}
public TestEntity (int v) {this.val = v;}
public int val = 987;
public int getVal () {return val;}
public void setVal (int i) {this.val = i;}
}
import java.awt.Dimension;
import java.util.*;
public class BigEntity {
private List props = new LinkedList();
public List getProperties () {return props;}
public void setProperties (List props) {this.props = props;}
private String name = "Jo";
public String getname () {return name;}
public void setname (String n) {this.name = n;}
public BigEntity () {
props.add(new TestEntity());
props.add(new TestEntity(55));
}
public BigEntity (String name) {this.name = name;}
public boolean equals (Object other) {
boolean ret = this == other;
if (!ret && other instanceof BigEntity) {
BigEntity o = (BigEntity)other;
ret = this.name == null ? o.name == null : this.name.equals(o.name);
}
return ret;
}
public int hashCode () {return 3 * (name == null ? 0 : name.hashCode());}
public String toString () {return "#<BigEntity name=\"" + name + "\">";}
}
import java.io.*;
import java.util.*;
import org.jvyaml.YAML;
public class MyDriver {
public static void main (String[] args) { try {
//// Dump test:
BigEntity e1 = new BigEntity();
String filename = "t.yaml";
YAML.dump(e1, new FileWriter(filename));
System.out.println(YAML.dump(e1)); // debug
//// Load Test:
BigEntity e2 = (BigEntity)YAML.load(new FileReader(filename));
System.out.println("e2 = " + e2);
} catch (Exception e) {e.printStackTrace();} }
}
And when I run java MyDriver, this is the output:
$ java MyDriver
--- !java/object:BigEntity
name: Jo
properties: !!seq:java.util.LinkedList
- !java/object:TestEntity
&id1 val: 987
- !java/object:TestEntity
*id1: 55
while scanning a node
expected the node content, but found org.jvyaml.tokens.BlockEntryToken
org.jvyaml.ParserException: ParserException while scanning a node we had
this expected the node content, but found
org.jvyaml.tokens.BlockEntryToken
at org.jvyaml.ParserImpl$10.produce(ParserImpl.java:261)
at org.jvyaml.ParserImpl.parseStreamNext(ParserImpl.java:796)
at org.jvyaml.ParserImpl.peekEvent(ParserImpl.java:747)
at org.jvyaml.ComposerImpl.composeNode(ComposerImpl.java:106)
at org.jvyaml.ComposerImpl.composeNode(ComposerImpl.java:168)
at org.jvyaml.ComposerImpl.composeDocument(ComposerImpl.java:95)
at org.jvyaml.ComposerImpl.getNode(ComposerImpl.java:71)
at org.jvyaml.BaseConstructorImpl.getData(BaseConstructorImpl.java:88)
at org.jvyaml.YAML.load(YAML.java:188)
at org.jvyaml.YAML.load(YAML.java:165)
at MyDriver.main(MyDriver.java:12)
Can anyone please explain what I'm doing wrong.
Can anyone explain why in the entity dump (first part of test run
output), I'm getting &id1 and *id1 ??
Thanks in advance
Zen
--
Homepage: www.SoulSound.net -- Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/