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 9232323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:17:12+00:00 2026-06-18T06:17:12+00:00

I have an ArrayList which stores a custom object. I want to serialize that

  • 0

I have an ArrayList which stores a custom object. I want to serialize that ArrayList to a string so I can save it inside the Application settings.

This question looks to resolve it, but is in java. And I am not smart with XML, so could someone help out?
Serialize an ArrayList of Date object type

I have my ArrayList setup:

...
MyObject tempObj = new MyObject("something",1,"something");
MyCollection.Add(tempObj);
...

And I originally had this. It outputs the string, but the object isn’t there:

    private string SerializeArrayList(ArrayList obj)
    {
            System.Xml.XmlDocument doc = new XmlDocument();
            Type[] extraTypes = new Type[1];
            extraTypes[0] = typeof(MyObject);
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ArrayList), extraTypes);
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            try
            {
                serializer.Serialize(stream, obj);
                stream.Position = 0;
                doc.Load(stream);
                return doc.InnerXml;
            }
            catch { throw; }
            finally
            {
                stream.Close();
                stream.Dispose();
            }
}

EDIT: Code request

    public class MyObject
    {
        private string eN;      
        private Boolean bE;          
        private int min;         
        private Boolean bot;       
        private string onE;         


        public MyObject(string na, Boolean b)
        {
          ...
        }


        public MyObject()
        {
        }

        public string GetSomething()
        {
            ...
  • 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-18T06:17:14+00:00Added an answer on June 18, 2026 at 6:17 am

    I tested your code and it seems to work ok, as long as you have [Serializable] on your object.

    Also if you are trying to Serialize the fields, you will have to make them public properties.

    My Test:

        ArrayList array = new ArrayList();
        Rules tempObj = new Rules { onE = "Value", min = 45, eN = "Value" };
        array.Add(tempObj);
        string result = SerializeArrayList(array);
    
        private string SerializeArrayList(ArrayList obj)
        {
            XmlDocument doc = new XmlDocument();
            XmlSerializer serializer = new XmlSerializer(typeof(ArrayList), new Type[]{typeof(Rules)});
            using (MemoryStream stream = new System.IO.MemoryStream())
            {
                try
                {
                    serializer.Serialize(stream, obj);
                    stream.Position = 0;
                    doc.Load(stream);
                    return doc.InnerXml;
                }
                catch (Exception ex)
                {
                }
            }
            return string.Empty;
        }
    

    Object:

    [Serializable]
    [XmlType(TypeName = "Rules")]
    public class Rules
    {
        // Make fields propertys so they will be serialized
        public string eN { get; set; }      //Name
        public Boolean bE { get; set; }     //Whether blocked entirely
        public int min { get; set; }        //Minutes they are allowed if blocked
        public Boolean bot { get; set; }    //Create notification if allowance exceed
        public string onE { get; set; }     //Nothing or CLOSE Process
    
        public Rules(string na, Boolean b)
        {
    
        }
    
        public Rules()
        {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ArrayList which stores Area names. I want to check this list
I have an application which stores values of a certain kind of object (say,
I have a custom model, which internally uses HashMap<String, Object> to store the data.
I have an ArrayList that stores 100,000+ numbers inside of it. Each number is
To make things simple, I have an ArrayList called items (which stores a string
I have an object called Route which stores an ArrayList of RouteStep objects. A
At the moment inside the class I have ArrayList which the objects are stored
I have arraylist myorderdata . I want to retrieve this arraylist to one String
In my code, I have used ArrayList which stores the number format like '$0.00
I have an ArrayList in which I add BigDecimals. My problem is, that the

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.