PBMCube / as3yaml

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

Ability to specify which key oder to use when encoding YAML mappings #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
in some cases, one might want to have a specific sorting of the keys when
encoding yaml objects - in my case the order is important to keep the diffs
to a minimum between various versions of the generated yaml.

ordering the keys is currently only possible by just adding the keys in
that specific order in a HashMap for example. but the class name HashMap
(and documentation) suggests that the order of the entries is specified by
some hashing algorithm (i know its currently not doing any hashing). the
point is that one can't rely that HashMap will always return the entries in
the order they were put in, because eventually (in the future) it could
really implement some hashing.

Original issue reported on code.google.com by schizosfera@gmail.com on 16 Oct 2009 at 10:04

GoogleCodeExporter commented 9 years ago
I agree.  I actually want to get rid of the HashMap class altogether and 
replace it
with Dictionary and OrderedObject (this is a simple class that is available in 
the
Flex framework that maintains the order in which properties were added).  Then 
I'll
add an option in the config class that specifies which option to use when 
decoding
(Dictionary where order does not matter, OrderedObject where it does).

Original comment by dwischu...@gmail.com on 16 Oct 2009 at 4:21

GoogleCodeExporter commented 9 years ago
i actually meant encoding ;)
i couldn't find the OrderedObject class in the flex reference - watch for 
dependencies :P

Original comment by schizosfera@gmail.com on 16 Oct 2009 at 4:52

GoogleCodeExporter commented 9 years ago
Definitely.  I'm just going to grab the class and add it to the yaml lib (as I 
did
for the Base64 classes).

On the encoding side you'll have control over which classes you encode.  I'll 
just
need to update the encoder so that Dictionary and OrderedObject get serialized 
as
plain yaml objects rather than custom actionscript objects.  On the decoding 
side
I'll need to add the option for maintaining order because right now everything 
gets
turned into a Dictionary, which does not guarantee order (actually it's 
basically
guaranteed to lose the order).  So if you were to specify in the config that 
order
should be maintained, the decoder would return OrderedObjects rather than 
Dictionary
objects so you would be able to do a complete roundtrip without losing order.

Best,

Derek

Original comment by dwischu...@gmail.com on 16 Oct 2009 at 5:14

GoogleCodeExporter commented 9 years ago
any update on this issue? it's something i really need. if you don't have the 
time,
i'll probably have to hack this myself in my local copy of the source.

Original comment by schizosfera@gmail.com on 3 Nov 2009 at 2:16