UcasRichard / snakeyaml

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

Do not dump reduntant explicit tag for a scalar with the same implicit tag #128

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In the JodaTimeExampleTest.testLoadBean() a redundant !!timestamp tag is dumped 
for a scalar which may use implicit same tag.
Without this redundant tag the JavaBean property cannot be loaded.

The issue exposed when the the default flow style has been changed to BLOCK. 
With this flow the tag is not issued but the instance cannot be created.

This is unclear. This has to be either explained or fixed.

Original issue reported on code.google.com by py4fun@gmail.com on 13 Jul 2011 at 4:29

GoogleCodeExporter commented 9 years ago
I have added FIXME statements in clone:
http://code.google.com/r/py4fun-deprecate-javabeandumper/source/browse

http://code.google.com/r/py4fun-deprecate-javabeandumper/source/browse/src/test/
java/examples/jodatime/JodaTimeExampleTest.java

Original comment by py4fun@gmail.com on 13 Jul 2011 at 4:39

GoogleCodeExporter commented 9 years ago
I have more information now. The title is wrong. The tag is not redundant.
Explicit tag must be used. Otherwise implicit tags are ignored for JavaBean 
properties.
Joda's DateTime cannot be created from a scalar because it does not have the 
corresponding contructor. Unfortunately, changing the default flow style to 
BLOCK caused the tag to disappear.
The test now reflects the bug.

Original comment by py4fun@gmail.com on 14 Jul 2011 at 8:40

GoogleCodeExporter commented 9 years ago
Read from PyYAML: http://pyyaml.org/wiki/PyYAMLDocumentation
"The implicit flag of a scalar event is a pair of boolean values that indicate 
if the tag may be omitted when the scalar is emitted in a plain and non-plain 
style correspondingly."
The event is (run the test to see it):
<org.yaml.snakeyaml.events.ScalarEvent(anchor=null, 
tag=tag:yaml.org,2002:timestamp, implicit=[true, false], 
value=2001-09-09T01:46:40Z)>

Indeed the tag is not omitted when AUTO flow is used (and the scalar is 
non-plain -  it is single quoted). But there is no tag when BLOCK flow is used 
(and the scalar is plain).
So it works exactly as it described. But why the AUTO flow style makes the 
scalar single quoted ?

Original comment by py4fun@gmail.com on 15 Jul 2011 at 4:59

GoogleCodeExporter commented 9 years ago
The AUTO flow style makes the scalar single quoted because a timestamp contains 
':' characters which should be escapes in the flow style.

Original comment by py4fun@gmail.com on 26 Jul 2011 at 9:47

GoogleCodeExporter commented 9 years ago
The problem is explained in the comments. Proposed solution does not rely on
implicit or explicit tag. See:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/examples/jodatime
/JodaTimeExampleTest.java#59

(method testLoadBeanWithBlockFlow())

Original comment by py4fun@gmail.com on 26 Jul 2011 at 12:42