SamuraiAku / SPDX.jl

Provides for the creation, reading and writing of SPDX files in multiple file formats. Written in pure Julia.
MIT License
5 stars 1 forks source link

Order of relationships written to JSON file may be different from the order in which they were read #20

Closed SamuraiAku closed 7 months ago

SamuraiAku commented 1 year ago

Read a JSON file, then write it back out to another JSON file, then read that second file. The order of entries the Relationships vector is different. It doesn't matter at all from a data model point of view, but why does it do that?

hannahilea commented 1 year ago

When using JSON.jl, to get back the objects in order you can pass in a dicttype arg:

you can pass dicttype=DataStructures.OrderedDict to maintain the insertion order of the items in the object;

ref https://github.com/JuliaIO/JSON.jl

hannahilea commented 1 year ago

(As I understand it, the reason is that the JSON spec says that objects are un-ordered collections, even though various implementations do provide functionality to read/write in ordered ways)

SamuraiAku commented 1 year ago

I use the orderedDict in SPDX.jl and it works well. I think the bug is in how I'm creating the relationship vector in my own code. Need to review more and document a good example case.

I care about the order because it allows for a user to read in a file, make some small modifications such as update the version and checksum, and then write it all back to file and only those changed elements show up in a git diff. If I don't use OrderedDict there's no guarantee that would happen.

SamuraiAku commented 7 months ago

I tried recreating the issue and I can't do it. It doesn't matter anymore since I've updated the internal compare functions so they can handle out of order vectors. Close it for now, reopen if I find the bug again and I think it's important.