Closed GoogleCodeExporter closed 9 years ago
see attached test case
Original comment by nvoy...@gmail.com
on 4 Mar 2015 at 11:14
As far as I can see the test outputs:
!!org.yaml.snakeyaml.issues.issue208.CompositeEntity
name: CompositeEntity
param1: null
parent: null
What is wrong with it ?
Original comment by py4fun@gmail.com
on 4 Mar 2015 at 1:44
Few month ago I work with Yaml in Ruby and had the same structure in basis. I
expect to see collection of Entities inside Yaml dump and of course its
correctly loading from Yaml-file.
I rewrite test method to show what I wait to see ..
public void testEntityYaml() throws IOException {
CompositeEntity entity = new CompositeEntity();
entity.setName("CompositeEntity");
CompositeEntity e = (CompositeEntity) entity.add(new CompositeEntity());
e.setName("1.1");
e = (CompositeEntity) entity.add(new CompositeEntity());
e.setName("1.2");
CompositeEntity e2 = (CompositeEntity) e.add(new CompositeEntity());
e2.setName("1.2.1");
e2 = (CompositeEntity) e.add(new CompositeEntity());
e2.setName("1.2.2");
YamlDatabase db = new YamlDatabase();
db.save(entity);
CompositeEntity entityFromYaml = (CompositeEntity) db.load(entity.getClass());
assertTrue(entityFromYaml.getName().equals(entity.getName()));
assertTrue(entityFromYaml.getEntitiesSize() == entity.getEntitiesSize());
assertTrue(entityFromYaml.getEntityAt(0).getName().equals(entity.getEntityAt(0).getName()));
CompositeEntity e2fromYaml = (CompositeEntity) entityFromYaml.getEntityAt(1);
e2fromYaml = (CompositeEntity) e2fromYaml.getEntityAt(1);
assertTrue(e2.getName().equals(entity.getEntityAt(0).getName()));
}
and now I wait to see something of this
!!org.yaml.snakeyaml.issues.issue208.CompositeEntity
name: CompositeEntity
param1: null
parent: null
entities:
- !!org.yaml.snakeyaml.issues.issue208.CompositeEntity
name: 1.1
param1: null
parent: null
entities: []
- !!org.yaml.snakeyaml.issues.issue208.CompositeEntity
name: 1.2.1
param1: null
parent: null
entities:[]
- !!org.yaml.snakeyaml.issues.issue208.CompositeEntity
name: 1.2.1
param1: null
parent: null
entities:[]
bellow you can see my old yaml-file example from Ruby
--- !ruby/hash:ISPS::Data::ProductRegistry::Products p1: &3147000 !ruby/object:ISPS::Core::Product custom_actions: {} components:
Original comment by nvoy...@gmail.com
on 4 Mar 2015 at 2:07
new JUnit test case
passed: assertTrue(entityFromYaml.getName().equals(entity.getName()));
fail: assertTrue(entityFromYaml.getEntitiesSize() == entity.getEntitiesSize());
must fail, because collection haven't saved:
assertTrue(entityFromYaml.getEntityAt(0).getName().equals(entity.getEntityAt(0).
getName()));
CompositeEntity e2fromYaml = (CompositeEntity) entityFromYaml.getEntityAt(1);
e2fromYaml = (CompositeEntity) e2fromYaml.getEntityAt(1);
assertTrue(e2.getName().equals(entity.getEntityAt(0).getName()));
Original comment by nvoy...@gmail.com
on 4 Mar 2015 at 2:13
Attachments:
Let's take a simple example
class Entity {
protected String name;
protected List
what must be outputed?
> !!Entity
> name: Entity
or
> !!Entity
> name: Entity
> entities:
> - !!Entity
> name: e1
> - !!Entity
> name: e2
how to I can get the second alternative output?
Original comment by nvoy...@gmail.com
on 4 Mar 2015 at 2:31
I see the point now.
CompositeEntity is not a JavaBean. It does not define setters and getters for
the exposed fields.
You can either to define your own way to (de)serialise the object or make it a
JavaBean.
Original comment by py4fun@gmail.com
on 4 Mar 2015 at 2:45
Now it works :) Thanks a lot and sorry for stupid question.
Original comment by nvoy...@gmail.com
on 4 Mar 2015 at 3:01
You are welcome. Next time it is better to ask general questions in the mailing
list.
Original comment by py4fun@gmail.com
on 4 Mar 2015 at 3:18
Original issue reported on code.google.com by
nvoy...@gmail.com
on 4 Mar 2015 at 10:48