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

Ignore some certain properties when serialized. #86

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

BinGuoGuo
Copy link

In our project,each fields and properties whose modifier is PUBLIC will be serialized as a string format.Of course,we could modify their modifier to INTERNAL ,even PRIVATE,to prevent to serialize the fields or properties you don't really want.But in some certain situations you must to make a data modified as PUBLIC,we can also use the following changes.
I added a custom attribute("NonToJsonAttribute") in project,and use reflection to avoid adding fields or attributes to a serialized collection.By this way,every fields and properties that marked with "NonToJson" attribute will not be serialized.
Below is the example-code:
interface ITest
{
int TestProperty { get; }
}
class Test : ITest
{
//The property what I want not to serialize
[NonToJson]
public int TestProperty => 0;
public int Other { get; set; } = 1;
}

    . . .

    Test t = new Test();
    string result = LitJson.JsonMapper.ToJson(t);

In our project,each fields and properties whose modifier is PUBLIC will be serialized as a string format.Of course,we could modify their modifier to INTERNAL ,even PRIVATE,to prevent to serialize the fields or properties you don't really want.But in some certain situations you must to make a data modified as PUBLIC,we can also use the following changes. 
I added a custom attribute("NonToJsonAttribute") in project,and use reflection to avoid adding fields or attributes to a serialized collection.By this way,every fields and properties that marked with "NonToJson" attribute will not be serialized.
Below is the example-code:
interface ITest
        {
            int TestProperty { get; }
        }
        class Test : ITest
        {
            //The property what I want not to serialize
            [NonToJson]
            public int TestProperty => 0;
            public int Other { get; set; } = 1;
        }

        . . .

        Test t = new Test();
        string result = LitJson.JsonMapper.ToJson(t);
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

Successfully merging this pull request may close these issues.

1 participant