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

Feature: support field serialization consistent with Unity #9

Open
BBI-YggyKing opened this issue May 21, 2014 · 3 comments
Open

Feature: support field serialization consistent with Unity #9

BBI-YggyKing opened this issue May 21, 2014 · 3 comments

Comments

@BBI-YggyKing
Copy link

By default Unity serializes public fields, as does LitJson. However the rules are a little more complicated. It should be possible to configure LitJson to directly mimic the serialization behaviour of Unity, most specifically to train it to respect the SerializeField attribute. (Note that this should be done without introducing a compile-time dependency between LitJson and UnityEngine, but rather by having a way to dynamically inject an attribute type or delegate to control what gets serialized.)

Unity will serialize the following types:

  • any Unity object
  • any custom class (but not struct) marked with System.Serializable attribute
  • basic value types (string, float, int, etc.)
  • Lists and arrays of serializable types

On these objects, the following will be serialized:

  • public fields of serializable types
  • private fields marked with the UnityEngine.SerializeField attribute
  • -not- properties

More information on serialization from the Unity tech blog.

@Mervill
Copy link
Owner

Mervill commented May 21, 2014

For insight, I'd suggest switching to text-based meta files and opening a file in notepad. Unity serializes all it's objects using the YAML format, which IIRC is a superset of Json, so developing a strategy here should be straightforward.

@BBI-YggyKing
Copy link
Author

The rules are simple enough, as outlined above. Right now there's no way to tell LitJson to serialize private fields, or to look for the SerializeField attribute. (I just hacked support for this into my local branch, but it's not done cleanly.)

@pedro15
Copy link

pedro15 commented Aug 23, 2017

mine are not serializing a private array list of a custom derived type. only public ones accepts it. any news ?

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

No branches or pull requests

3 participants