Closed rosostolato closed 6 years ago
It has indirect support for it. You can add it yourself using the provided extension methods. Example below
static void Main(String[] args){
NetJSON.CanSerialize = CanSerialize;
}
private static bool CanSerialize(MemberInfo memberInfo)
{
var attr = memberInfo.GetCustomAttribute<TestIgnoreAttribute>();
if(attr != null)
{
return false;
}
return true;
}
public class TestClassWithIgnoreAttr
{
[TestIgnore]
public int ID { get; set; }
}
public class TestIgnoreAttribute : Attribute
{
}
If the solution satisfy your question. Please help me close the issue.
The documentation is here: https://github.com/rpgmaker/NetJSON/wiki/Quick-Guide
NetJSON.CanSerialize
Great, I used the same JsonIgnore as attribute and now it ignores on serialization. But, I guess that was not my problem at all, it still throws exception.
Take a look at my models. Maybe it's not working with Icollections:
I had a exception when using Newtonsoft Json too, but it was resolved with JsonIgnore. And JsonIgnore is working here, I tested ignoring the Icollection in the first class and all worked. But with these collections it's not.
ICollection should work. Are you using the nuget package? If so, you might want to use the latest from the repo. I am waiting for a change to push the latest changes to nuget.
Thanks,
yes, I'm using from nuget
I tested now using just the first 2 classes and it's still getting exception.
Ignoring all collection it works
Are you testing using the latest code from the source code repo and not nuget? The latest code should work.
Thanks,
Ok, I'm downloading the last code from repo
Great! With the last repo it works!! Thank you a lot!
The latest code is now available on nuget: https://www.nuget.org/packages/NetJSON/
I'm trying to serialize a model that has children with reference to their parents, so I guess that is why it's throwing exception. On Newtonsoft Json I use [JsonIgnore] on parents reference and all works great. Does NetJson have a way to igonre them too?