-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Add JsonIgnore Attribute #7
base: develop
Are you sure you want to change the base?
Conversation
When JsonIgnore is applied to a field or property, that member is ignored when deserializing and/or serializing. You can specify JsonIgnoreWhen.Serializing to only ignore serialization, *.Deserializing to only ignore deserializing, or default which is to ignore the field either way. Added unit tests for JsonIgnore, mroe to come. Updated Makefile. Updated .gitignore to include debug and OSX files.
Added float to the base exporter table.
I like this IgnoreWhenSerializing/IgnoreWhenDeserializing. Any way to consolidate it with d141017 ? |
If you want to use this with the latest master copy the JsonAttribute.cs and then use this as your JsonMapper.cs: https://gist.github.com/lbv/87aa07d4f187743ef8ad Edit: Moved the code into a gist. |
This pull is a must. In my home version I also have a [JsonStrict] and [JsonInclude] attributes. I did this for cases for instances when I was inherent from a base class I had no control over. This allowed me to blacklist all properties and fields (strict) and then white list the properties I wanted (include). Would you mind adding this to your pull ? |
Hello, Sorry for the long silence. I like the idea of this request, especially if people find it useful in common scenarios, as illustrated by @NVentimiglia. My only question is about the name of the attributes. Are the Please bear with me, as it's been a long time I've coded in C# and followed the development of common JSON libraries for different languages. But if there is some type of consensus among JSON library writers, I'd be happy to follow it. I want to make LitJSON easy to use and a good community player. |
Im currently using This variant of LITJson. It includes a JsonIgnore annotation. |
I've added an attribute which can be applied to fields and properties to ignore them during JSON serialization and deserialization. Using
[JsonIgnore(JsonIgnoreWhen.Serializing)]
will not serialize the field but still deserialize data into it.[JsonIgnore(JsonIgnoreWhen.Deserializing)]
will serialize the field but not deserialize it. The default[JsonIgnore]
ignores the field during serialization and deserialization.I've also added some initial support for importing/exporting floats and signed long ints. I did this because LitJson works very well with Unity which uses floats for most floating-point numbers.
Unit tests also included.