ilmoeuro / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
0 stars 0 forks source link

Option to ignore unknown tags #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If the loader encounters a tag it cannot resolve to a java class an
exception is thrown. I need an option that causes the loader to ignore such
tags (and as a result use the default types for map, seq, str).

Example YAML input file:

center: !Point [1,1]
city: !Place 12345 Springfield

Now assume that we have a constructor defined for !Point but not !Place. If
I read this file, I get an exception. But I need the datastructure as
produced by:

Map<String, Object> map = ...
map.put("center", new Point(1,1));
map.put("city", "43925 Springfield");

It should simply ignore !Place and use String instead. If the unknown tag
is on a map/seq, it should use Map/List.

Original issue reported on code.google.com by smurn....@gmail.com on 13 Nov 2009 at 4:10

GoogleCodeExporter commented 9 years ago
The spec:
If a document contains unresolved tags, the YAML processor is unable to compose 
a
complete representation graph. In such a case, the YAML processor may compose an
partial representation, based on each node’s kind and allowing for 
non-specific tags. 

http://yaml.org/spec/1.1/#partial%20representation/

A complete representation is required in order to construct native data 
structures. 

It is the same as if you define a local tag with the meaning: "!Place" -> 
"!!str"

I am not really in favour of simply ignoring tags. But I will have a look how an
application can specify a flexible "tag policy" with minimum code.

Original comment by aso...@gmail.com on 13 Nov 2009 at 5:38

GoogleCodeExporter commented 9 years ago
I agree that ignoring tags should not be default behaviour. In my case, the 
data in
the files is presented to the user (after some processing). For the 
presentation its
not so important that the construction produces the right classes.

Just adding "!Place" -> "!!str" does not help in my particular case. I cannot 
control
what tags are used in the input files.

I'd implement it my self, but I don't want to mess with Constructor class 
without
your guidance.

Original comment by smurn....@gmail.com on 13 Nov 2009 at 7:33

GoogleCodeExporter commented 9 years ago
If it not important that the construction produces the right classes can you 
just 
create nodes ? 
(http://code.google.com/p/snakeyaml/wiki/Documentation#Low_Level_API)
I still do not get how to define:
- which tags should be ignored
- which tags must be respected
- which tags must cause a failure if they cannot be properly processed
If the tag is ignored, should the implicit types be respected ? (123 -> Integer)

The term "unknown tag" is unclear for me since a local tag can be defined in 
the 
document. I think you are only talking about the global tags (with the class 
name). 
But then the example is not very representative.

Original comment by py4fun@gmail.com on 16 Nov 2009 at 9:46

GoogleCodeExporter commented 9 years ago
I have to read data structures that were serialized by another application. I 
have
some classes (the ones I care about) that I know are part of both apps. So those
could be constructed during loading. For all the other classes its enough if I 
can
make a nice print-out of the data. So my idea was to simply use the default 
str, map,
seq types for them. 

I see now that this was a bad idea. The main problem is that the default str 
map seq
types will not be assignable to my bean properties because they use 
incompatible data
types.

Unless you come up with some better idea I suggest closing this issue.
Seems I have to manually extract the data I need from the Low level API after 
all.

Original comment by smurn....@gmail.com on 22 Nov 2009 at 4:02

GoogleCodeExporter commented 9 years ago

Original comment by py4fun@gmail.com on 23 Nov 2009 at 8:44