Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case class not serialising in order #208

Open
shrikantjoveo opened this issue Sep 5, 2017 · 3 comments
Open

Case class not serialising in order #208

shrikantjoveo opened this issue Sep 5, 2017 · 3 comments

Comments

@shrikantjoveo
Copy link

I have a case class
case class A(a: Int, b: Int)

I m seeing sometimes that the resulting serialized value is
{a:1,b:1} and sometimes {b:1,a:1}

Does salat provide any guarantees as to the order of serialization in a case class? Can this be done?

@noahlz
Copy link
Contributor

noahlz commented Sep 5, 2017

Are you using salat for serialization into mongo, or for generating JSON from case classes?

In either case, I'm not aware of a guarantee that order of field declaration is preserved.

Might I ask what problem this is causing for you?

@shrikantjoveo
Copy link
Author

We are using salat for serialization of a case class which is used as a compound key for inserting document into a Mongo collection.
Since, the order of field declaration is not preserved, Multiple documents are getting inserted into Mongo Collection with same value for Compound Key.

@noahlz
Copy link
Contributor

noahlz commented Sep 7, 2017

This is somewhat related to #110

Field order preservation has not been a guarantee of Salat, and to be fair it seems that at the time Salat was first written Mongo itself did not support it. Salat itself does not rely on ordinal fields in the BSON serialized form, as it uses field names to map values from the DBObject to the case class.

You are welcome to dig around in Mongo source and propose a fix.
Since Salat is a community/volunteer project, I can't offer a turn-around time for resolving this otherwise.

I suggest that the Context needs a new configuration option for serialization, something like "ordinal fields = true." I would prefer this because of the potential overhead of maintaining field order (it might not be that big, of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants