Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:05:08+00:00 2026-06-01T11:05:08+00:00

I am using the .net datacontractjsonserializer to serialize my list of objects to a

  • 0

I am using the .net datacontractjsonserializer to serialize my list of objects to a JSON string, but there are certain public properties that I don’t want to serialize, how to prevent the datacontractjsonserializer from serializing these properties?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:05:09+00:00Added an answer on June 1, 2026 at 11:05 am

    There are two approaches when it comes to serializing with the .NET serializers:

    White-listing of properties:

    This is the recommenden approach. You mark your class explicitly with the DataContract attribute. With this, only properties that are marked with the DataMember attribute will be included in the output.

    Instead of doing a black list of properties that you don’t want to serialize, it’s better to do a white list and mark all properties you DO want to be serialized. This is more safe, because it requires the developer to explicitly state that they want a property to be serialized when introducing a new property.

    Black-listing of properties:

    If you really want to do black listing, you can use the IgnoreDataMember attribute as pointed out by others. In this case you don’t need to (and shouldn’t) mark your class with the DataContract attribute. Instead you mark the properties you want to have excluded with IgnoreDataMember.

    I hope this helps a bit to explain the choices and their advantages/disadvantages.

    Edit: Expanded my answer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using DataContractJsonSerializer to serialize a dictionary, like so: [CollectionDataContract] public class Clazz :
I've got the following JSON string to deserialize: [{application_id:1,application_package:abc},{application_id:2,application_package:xyz}] I'm using DataContractJsonSerializer method. It
I'd prefer to use Microsofts System.Runtime.Serialization.Json.DataContractJsonSerializer to serialize my objects in JSON so I
It seems that serializing Entity Framework objects into JSON is not possible using either
Iam using .NET 3.5. I have asp.net mvc app. There is base controller: public
I am using .NET's IIdentity and IPrincipal objects for role based security, and I
I am unable to convert JSON string to .net object in asp.net. I am
I can't get access to the DataContractJsonSerializer method from System.Runtime.Serialization.Json If I do: using
Using .net 2.0 is there a way to obtain the text to display, for
I have an ASP.NET webservice method that returns a generics list (List'<'Construct>) serialized as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.