Question about type tags

William Spitzak <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
A much more interesting question about yaml:

I doubt we are unique in that the data we wish to store is an array of 
objects, all of them are different subclasses of some base object, and 
the fields of these subclasses are different, and "which subclass" is 
not predictable.

What I propose to do to write an array containing them like this (where 
both classes have a 'name' field, but class A has an 'a' field and class 
  B has a 'b' field:

- !A {name: nameofa, a: value of a}
- !B {name: nameofb, b: value of b}
- !A {name: nameofa2, a: value}
...

Is this the planned usage of the type tags? Note that the 'b' field will 
produce an error if placed in the A object.

Another post here suggested this:

- {type: A, name: nameofa, a: value of a}
- {type: B, name: nameofb, b: value of b}
- {type: A, name: nameofa2, a: value}
...

However this seems to require that "type" be first, at least if we want 
to read directly into the object, rather than have to make a temporary 
name+value structure and then set the object after I get the type. 
Obviously I can force the yaml file to have the type first but this 
seems inconsistent with yaml's design.

Am I using it as intended? Any other alternatives I missed?

One thing that attracted me to yaml was this tagging, which json lacks, 
because it looked like the correct way to do this.

Bill Spitzak
Rhythm & Hues software dept


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.