How not to serialize some attributes in Restful calls (C# + WCF + JSON)?

Asked

Viewed 537 times

3

In the example below, how to do not serialize an attribute.

I believe I’m looking for the equivalent of java syntax:

For classes: @Jsonignoreproperties(ignoreUnknown = true); For attributes: @Jsonignore for attribute.

public class SomeFakeClass
{    
    public int ID { get; set; }

    public string Text { get; set; }

    public decimal Value { get; set; }
}

How to do not serialize 1: the class, 2:a particular attribute.

From now on thank!

  • Which Voce library is using to serialize the object?

1 answer

3


Try to use the attribute IgnoreDataMemberAttribute on the property.

Example with the property ID of your class:

public class SomeFakeClass
{
    [IgnoreDataMember]
    public int ID { get; set; }

    public string Text { get; set; }

    public decimal Value { get; set; }
}
  • Perfect Miguel! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.