UcasRichard / snakeyaml

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

Serialized Java classes should have an explicitly-formatted tag #57

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I propose that instead of just serializing a Java object with the raw class 
name, there should be a 
formatted tag structure that can be parsed to clearly identify it's a Java 
object.

For example, the following tag:

!!org.foo.Bar

does not indicate to other parsers that it's representing the internal state of 
a Java object. The 
data could probably be reconstituted as an arbitrary structure in those 
parsers, but it would be 
nice if this tag made it clear it's a Java class:

!!java:org.foo.Bar

So that if a parser wanted to add support for Java classes, it would just need 
to register a handler 
that knows how to deal with "java" tagged elements.

Disclaimer: I'm no YAML expert, so there may be a more appropriate way to say 
"the data 
contained below is from a Java object of class X". But at the very least, it 
should be possible to 
inspect the YAML output and know (without attempting a Class.forName) that 
org.foo.Bar is a 
Java class.

Original issue reported on code.google.com by headius%...@gtempaccount.com on 19 Mar 2010 at 7:07

GoogleCodeExporter commented 9 years ago
Introduction of namespaces may give some advantages. For instance

!!java/javabean:org.foo.Bar -> to create a JavaBean
!!java/factory:org.foo.Bar.create -> to call a static method with the scalar as 
the
argument
!!java/javabean/private:org.foo.Bar -> to create a non-JavaBean (for issue 55)
!!java/javabean/annotation:org.foo.Bar -> use annotations
!!java/custom:org.foo.Bar -> use custom way

But it opens a question what to do when the namespace is not supported. Fail ? 
Guess ?
There is long-standing issue to ignore unknown tags (#39)

Original comment by aso...@gmail.com on 21 Mar 2010 at 11:16