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

  • Home
  • SEARCH
  • 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 6066623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:31:14+00:00 2026-05-23T09:31:14+00:00

I read several threads on serialization I found here, but they did not answer

  • 0

I read several threads on serialization I found here, but they did not answer my question.

I need a simple serialization library, that would reflect over the properties marked with certain attribute and store their values as a string. All the properties are either directly strings or directly convertable to and from string (built-in value types, bool, etc.). It should also understand simple containers (like generic lists) and serialize those content.

The control I need over the serialization is to indicate what properties are to be serialized (only those decorated with an attribute) and I also must be able to indicate that certain properties are serialized as the last ones: during serialization they must be also deserialized as the last ones.

The format does not matter, just normal param1=val1, param2=val2 would do, JSON would also do, as well as XML or even escaped or encoded binary format. Important is that I can have all my settings in one string I can easily store and load in my application.

Any ideas?

  • 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-05-23T09:31:14+00:00Added an answer on May 23, 2026 at 9:31 am

    The DataContractSerializer does that – you decorate the classes to be serialized with [DataContract], and only the members which you want serialized with [DataMember]. You can also control the order of the serialization via the Order property of the DataMember attribute.

    The DataContractSerializer (DCS) always serializes the objects as XML, but the XML it uses can be both the “normal” XML with tags, or a more compact binary format, depending on the XmlWriter you pass to it during serialization (and XmlReader during deserialization). Another option which gives you more control over the produced XML (but it’s not as performant) is the XmlSerializer class, which has its own attributes for controlling the serialization.

    The code below shows an example of a DCS-serializable type and its serialization:

        [DataContract]
        public class Person
        {
            [DataMember(Order = 1)]
            public string Name;
            [DataMember(Order = 2)]
            public int Age;
            [DataMember(Order = 3)]
            public Address Address;
        }
        [DataContract]
        public class Address
        {
            [DataMember(Order = 1)]
            public string Street;
            [DataMember(Order = 2)]
            public string City;
            [DataMember(Order = 3)]
            public string State;
        }
        public static void Test()
        {
            MemoryStream ms = new MemoryStream();
            XmlWriterSettings ws = new XmlWriterSettings
            {
                Indent = true,
                IndentChars = "  ",
                Encoding = Encoding.UTF8,
            };
            XmlWriter w = XmlWriter.Create(ms, ws);
            DataContractSerializer dcs = new DataContractSerializer(typeof(Person));
            Person person = new Person
            {
                Name = "John",
                Age = 22,
                Address = new Address
                {
                    Street = "1 Main St.",
                    City = "Springfield",
                    State = "ZZ",
                }
            };
            dcs.WriteObject(w, person);
            w.Flush();
            Console.WriteLine("Serialized:");
            Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
            ms.Position = 0;
            XmlReader r = XmlReader.Create(ms);
            Person deserialized = (Person)dcs.ReadObject(r);
            Console.WriteLine(deserialized);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read several threads dealing with similar issues on here, but I just can't
I've read several questions here concerning Tomcat and logging but I still really don't
I read several threads on here about structs (one about mutable structs) and I
I've read several threads about this topic and need some clarification on a few
I've read and re-read Java Concurrency in Practice, I've read several threads here on
I've read the the restrictions for EJBs and several answers here on stackoverflow but
I have read several post on both matters but I haven't seen anyone comparing
I've read several articles on this issue, and technically speaking, all they end up
I've read several other questions about material in order to learn RoR. But my
Following the discussions here on SO I already read several times the remark that

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.