if object referenced from generic collection dumping may erase tags and prevent future loading
Closed this issue · 6 comments
GoogleCodeExporter commented
Assume Java Be�an has some property of type Collection<SomeRealClass> and this
collection has object referenced from some where else in the Object-Tree we are
going to dump.
Depending on the Object-Tree and order of dumping resulting dump may fail
during load.
It will happen because of erased tags.
Original issue reported on code.google.com by alexande...@gmail.com
on 1 Sep 2010 at 2:03
GoogleCodeExporter commented
see example
http://code.google.com/p/snakeyaml/source/detail?r=96cd1acce41722c056e582270aee1
47bd16cac9c
Original comment by alexande...@gmail.com
on 1 Sep 2010 at 2:10
- Added labels: ****
- Removed labels: ****
GoogleCodeExporter commented
I see that GeneralAccount does not get a tag because its class is the same as
specified in the collection.
Loader does not see that GeneralAccount is not a map (with 'name' key) but a
JavaBean with 'name' property.
Original comment by py4fun@gmail.com
on 1 Sep 2010 at 5:13
- Changed state: Started
- Added labels: ****
- Removed labels: ****
GoogleCodeExporter commented
SuperSaverAccount is dumped with name=General instead of proper SuperSaver
Original comment by py4fun@gmail.com
on 1 Sep 2010 at 5:27
- Added labels: ****
- Removed labels: ****
GoogleCodeExporter commented
Shame on me - I forgot to change package name..... sorry
Thx for the fix.
Have not noticed the name thing. Actually nice that it came out.
I might have an idea why ;) I think it would he nice to formalize it as a
separate issue.
Back to aliased thing...
You are right. Tag "erased" when Collection<GeneralAccount> serialized.
But when Collection<Account> property name starts with 'a' it is dumped and as
a result loaded first.
So loader can not guess the real class for the provided map... Loading fails.
It might be even more fun when you change type Collection<Account> to
Collection or Collection<?>. During loading that Collection will containe not
only Account but Map also. Loading most probably will fail anyway when
Collection<GeneralAccount> is composed.
But when we give name for the Collection<GeneralAccount> starting with 'a' and
for the Collection<Account> starting with 'b. First Collection<GeneralAccount>
serialized. Loading will be successful. It is because missing tag will be
substituted with determined class. Created object then will be added to
Collection<Account> without any problem since GeneralAccount implements Account.
I think in first case tag should not be erased. I have a solution, but still
checking if more general changes could be done to fix it.
Hope the explanation is not too messy ;)
Original comment by alexande...@gmail.com
on 1 Sep 2010 at 8:54
- Added labels: ****
- Removed labels: ****
GoogleCodeExporter commented
Seems like even if GeneralAccount has associated CustomTag same thing happens -
it is erased.
Original comment by alexande...@gmail.com
on 2 Sep 2010 at 8:39
- Added labels: ****
- Removed labels: ****
GoogleCodeExporter commented
This issue was closed by revision 1af98fbf8c.
Original comment by alexande...@gmail.com
on 6 Sep 2010 at 1:35
- Changed state: Fixed
- Added labels: ****
- Removed labels: ****