Ah, you are right that it might not be human-friendly. I don't want to rely on the order, but for (file) versioning it is quite valuable. (or rather changing the order can easily make versioning quite worthless).
I can manually sort it, but it creates a lot of mess: (NeoJSONWriter on: stream) prettyPrint: true; for: Something do: [ :mapping | mapping mapInstVars: (mapping identifier instVarNames \ #(unwanted)) sorted ]; for: Otherthing do: [ :mapping | mapping mapInstVars: mapping identifier instVarNames sorted ]; for: Point do: [ :mapping | mapping mapInstVars: mapping identifier instVarNames sorted ]; nextPut: anObject. I'd much rather have the following: (NeoJSONWriter on: stream) prettyPrint: true; sorted: true; for: Something do: [ :mapping | mapping mapInstVars: mapping identifier instVarNames \ #(unwanted) ]; mapInstVarsFor: Otherthing; mapInstVarsFor: Point; nextPut: anObject. or more fine-grained, although the above is imo nicer: (NeoJSONWriter on: stream) prettyPrint: true; for: Something do: [ :mapping | mapping mapInstVars: (mapping identifier instVarNames \ #(unwanted)) sorted ]; mapInstVarsFor: Otherthing sorted: true; mapInstVarsFor: Point sorted: true; nextPut: anObject. (or mapSortedInstVarsFor: or something).. Peter On Wed, Jul 25, 2018 at 11:20 AM, Sven Van Caekenberghe <s...@stfx.eu> wrote: > From json.org > > "An object is an unordered set of name/value pairs." > > IOW, it is not in the spec, it would be dangerous to rely up it in any way > (not that you are suggesting that). It might look better sometimes, but > even then alphabetic sorting might not be the most human friendly or most > meaningful. > > Note that 'properties' in NeoJSONMapping is an OrderedCollection, so it > keeps it order. So if you add them in the right order, that would do it. > > > On 25 Jul 2018, at 11:12, Peter Uhnák <i.uh...@gmail.com> wrote: > > > > Hi, > > > > would it be possible to provide option to automatically sort instance > variables when serializing objects? > > > > Either always sorted > > > > NeoJSONObjectMapping>>writeObject: anObject on: jsonWriter > > jsonWriter writeMapStreamingDo: [ :jsonMapWriter | > > (properties sorted: #propertyName ascending) do: [ :each | > > each writeObject: anObject on: jsonMapWriter ] ] > > > > or put it behind some sortProperties boolean flag. (atm I don't see any > downsides in having sort always enabled) > > Speed ? > A false suggestion that is part of the spec ? > > > Thanks, > > Peter > > >