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

Enum serialisation and deserialisation is not complementary #33

Closed
anuraags opened this issue Nov 23, 2016 · 5 comments
Closed

Enum serialisation and deserialisation is not complementary #33

anuraags opened this issue Nov 23, 2016 · 5 comments

Comments

@anuraags
Copy link

anuraags commented Nov 23, 2016

I'm not sure if complementary is the word here (invertible maybe?)

If I declare a union such as this:

union GraphType {
  Void area;
  Void line;
  Void zones;
  Void onoff;
};
struct Foo {
   GraphType graphType;
};

It reads it in from json as for example "graphType": "area"

but when it serialises back to json it becomes

"graphType": {
   "disc": "AREA"
}

It seems like serialisation and deserialisation should be the reverse of each other?

@anuraags
Copy link
Author

I see that this is probably an artefact of using unions to define enums?

@timbod7
Copy link
Collaborator

timbod7 commented Nov 23, 2016

No. This should definite work as you expect - ie the data should "round trip" through the serialisation. Seems like a bug.

But... there's something strange about your serialised data:

"graphType": {
   "disc": "AREA"
}

Did you perhaps use gson to serialise the java object, rather than calling the ADL generated serialisation code?

@anuraags
Copy link
Author

Hmmmm....this is in the context of a http response. So I just return the adl generated object and let the http server work out the serialisation by itself. And I believe you're right, the http server does indeed use gson for the serialisation.

So you think I should first calle object.jsonBinding().toJson() before returning?

@timbod7
Copy link
Collaborator

timbod7 commented Nov 23, 2016

Yes. You should be calling object.jsonBinding().toJson() to generage the json.

These two function:

MyClass.jsonBinding().toJson(...)
MyClass.jsonBinding().fromJson(...)

should be inverses. However, there are (by design) not consistent with the json produced by

Gson gson = new GsonBuilder().create();
gson.toJson(...);

There's a few reasons for this: gson doesn't support generics easily, it's json isn't necessarily consistent with that produced by libraries for other languages etc.

It may be possible to create gson type adapters so that gson can generate ADL compatible json for ADL objects.

@timbod7
Copy link
Collaborator

timbod7 commented Nov 25, 2016

Not an ADL issue...

@timbod7 timbod7 closed this as completed Nov 25, 2016
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