Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

json serializer/deserializer question... #4

Open
natami opened this issue Mar 4, 2014 · 3 comments
Open

json serializer/deserializer question... #4

natami opened this issue Mar 4, 2014 · 3 comments

Comments

@natami
Copy link

natami commented Mar 4, 2014

Does the json serializer/deserializer support Enums?

eg. Java enums

@nexussays
Copy link
Owner

Yes, it does. You'll need to implement IJsonSerializable in your Enum; and if you want to use ObjectUtils to parse the JSON back into a typed object, add a static fromNative(Object):Object method .

I just fixed a bug with Enum.fromString, so either be sure you have the latest version or parse the enum from the value instead.

@natami
Copy link
Author

natami commented Mar 5, 2014

Hi, Malachi!

Great - just what i was looking for ;)

What about circular references support?
- In java / hibernate world we often use bi-directional mapping in our models, which I have not found any JsonDeserializer in AS3 able to handle.

Currently the workaround on the server side using Jackson (Json library) is to assign an id to each entity, see post:
http://stackoverflow.com/questions/16478476/jackson-circular-reference

Could something like that be implemented in your serializer?

  • I’m currently coding a tool to generate model and service classes from Java to AS3 and supports JSONRPC 2.0 on both java and AS3 side, where your Serializer would come ind very handy.

Regards!

On 05 Mar 2014, at 02:03, Malachi Griffie [email protected] wrote:

Yes, it does. You'll need to implement IJsonSerializable in your Enum; and if you want to use ObjectUtils to parse the JSON back into a typed object, add a static fromNative(Object):Object method .

I just fixed a bug with Enum.fromString, so either be sure you have the latest version or parse the enum from the value instead.


Reply to this email directly or view it on GitHub.

@nexussays
Copy link
Owner

There is unfortunately no support for circular references atm, so you'll probably just get a stack overflow.

I would recommend handling it in your model class since that is outside the scope of the serializer. (ie - I could just set any circular references to null; but the data will be lost since there is no way in JSON to represent a circular data structure.)

If you want to do it that way, just add a [Transient] metadata tag to the properties which hold circular references and they won't be serialized.

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

No branches or pull requests

2 participants