Coder Social home page Coder Social logo

Comments (10)

jrudolph avatar jrudolph commented on September 2, 2024

Thanks, that's an interesting observation. The minimum property should be that spray-json should make sure that a round-trip from an ordered collection to json and back should lead to the same result. That should be valid at least.

But I see how you would expect that the entries are also sorted on the json side of things.

The root cause is that toSeq directly maps over the given input iterable which moves from TreeSet to Set, because mapping a TreeSet without an ordering isn't possible.

Yep, indeed. I filed scala/bug#11987 but don't expect it can be fixed.

from spray-json.

jrudolph avatar jrudolph commented on September 2, 2024

Using JsArray(iterable.iterator.map(_.toJson).toVector) would fix it.

from spray-json.

swsnr avatar swsnr commented on September 2, 2024

@jrudolph That's more or less what we're using now.

from spray-json.

swsnr avatar swsnr commented on September 2, 2024

I think in this context it's also worth pointing out that spray-json should preserve the ordering in the source domain, that is, before converting elements of the collection to JSON, because the ordering of JSON values might be quite different from the ordering of the collection (think off, e.g. a TreeSet with an inverse ordering).

from spray-json.

jrudolph avatar jrudolph commented on September 2, 2024

I think in this context it's also worth pointing out that spray-json should preserve the ordering in the source domain, that is, before converting elements of the collection to JSON, because the ordering of JSON values might be quite different from the ordering of the collection (think off, e.g. a TreeSet with an inverse ordering).

Not sure what you mean. What would be the alternative?

from spray-json.

swsnr avatar swsnr commented on September 2, 2024

@jrudolph Well, when serializing a TreeSet you shouldn't order by the JSON value of its elements, but by the elements itself :)

from spray-json.

swsnr avatar swsnr commented on September 2, 2024

@jrudolph I'd just like to check what's the way forward here… do you expect me to open a pull request to fix this issue?

from spray-json.

jrudolph avatar jrudolph commented on September 2, 2024

Yes, please. In that case, I'd say adding .iterator would probably be safest.

from spray-json.

swsnr avatar swsnr commented on September 2, 2024

@jrudolph Will do.

from spray-json.

swsnr avatar swsnr commented on September 2, 2024

@jrudolph I opened #330.

from spray-json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.