Closed GoogleCodeExporter closed 9 years ago
Hello Stefan,
1) test is of course the best documentation. It really helps. Nevertheless some
more description gives the necessary context. Other users may be forwarded to
this issue by search engines when they are looking for the same problem. It
would be more informative if the title says something like this:
JavaBeans do not support SortedSet property when it is encoded as a sequence.
(This is a very specific case but the title is confusing)
2) in the patch Blog does not really conform to the JavaBeans standard. The
instance variable and the 'get' method return different classes (SortedSet and
Set)
3) If the property class is not an interface but an implementation (TreeSet for
instance) then it works properly. It does not work when you expect SnakeYAML to
make an intelligent guess which implementation of SortedSet to choose. Since
this is not the mapping (as it is defined in the YAML specification) but the
sequence it requires some help. Your patch works but we need some time to
analyse the problem to see the possible consequences.
Thank you for the contribution.
Original comment by py4fun@gmail.com
on 24 Nov 2010 at 12:11
ad 1) Sorry for writing that short of a description. I was kind of in a rush ;)
ad 2) My mistake, I was reusing the Blog class from another test case (see
issue #73). See the attached file, where this issue is resolved
ad 3) It also works with interfaces. Instantiating a TreeSet is not necessary
for the code to work, again see the attached file
Original comment by birnbu...@gmail.com
on 24 Nov 2010 at 9:36
Attachments:
(I have changed the title to be more specific)
I have added an example for the issue without any change in SnakeYAML:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue97/YamlSortedSetTest.java
The usecase is very specific. But the proposed patch changes general code. I am
afraid in this case we may end up with a lot of code which is hardly ever used.
I think it would be better if SnakeYAML stays simple and flexible enough to
allow any peculiar usage.
Please let us know whether it solves the problem and keep using SnakeYAML !
-
Andrey
P.S. The Zen of Python (http://www.python.org/dev/peps/pep-0020/)
- Explicit is better than implicit.
Original comment by py4fun@gmail.com
on 25 Nov 2010 at 9:41
Hi Andrey,
Thanks for pointing out the custom solution. I regard it as one of the strength
of the design of SnakeYAML that it is this flexible to accomodate such
extensions that easily.
If you want to include the patch into the core of SnakeYAML or not is of course
entirely up to you, I just want to clarify my use case a bit:
My domain model entities are mapped to a database using Hibernate. Some of the
sets contained in the model should be lazily loaded from the database and
should be rendered on the user interface with a consistent sorting. The only
way to guarantee this is to either use a List (which I don't want because it
requires an additional database column where the index is stored), decorate the
domain model (which I find awkward and complicated) - or to use a SortedSet.
HTH,
Stefan
Original comment by birnbu...@gmail.com
on 25 Nov 2010 at 11:34
I am closing the issue since you know how to proceed.
Hopefully we will have time to introduce and maintain a wiki page with many
"howto" examples. This is a perfect one.
Original comment by py4fun@gmail.com
on 25 Nov 2010 at 3:43
Original issue reported on code.google.com by
birnbu...@gmail.com
on 24 Nov 2010 at 10:10Attachments: