[Mono-bugs] [Bug 639381] New: Using DataContractJsonSerializer and knownTypes doesn't produce correct JSON

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Sep 14 17:11:20 EDT 2010



           Summary: Using DataContractJsonSerializer and knownTypes
                    doesn't produce correct JSON
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: Other
        OS/Version: Mac OS X 10.6
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: nutkracker at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us)
AppleWebKit/531.21.11 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10


    public partial class JSONTestDisplay : Form
        protected List<Type> _knownTypes = new List<Type>();
        protected DataContractJsonSerializer _json;
        protected Encoding _encoding = new ASCIIEncoding();

        public JSONTestDisplay()

        private void cmdSerialize_Click(object sender, EventArgs e)
            using (MemoryStream stream = new MemoryStream())
                //Serialize to memory
                _json.WriteObject(stream, new Noddy() { Id = 1, Name = "Test",
Age = 12, Shoesize = 34 });

                //Write memory to string
                txtJSON.Text = _encoding.GetString(stream.ToArray());

        private void JSONTestDisplay_Load(object sender, EventArgs e)
            _json = new DataContractJsonSerializer(typeof(object),_knownTypes);

        private void cmdDeserialize_Click(object sender, EventArgs e)
            using (MemoryStream memoryStream = new
                memoryStream.Position = 0;
                object outObject = _json.ReadObject(memoryStream);



    public class Noddy
        /// <summary>
        /// Constrcutor
        /// </summary>
        public Noddy() { }

        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public int Shoesize { get; set; }

The output from the above should produce:


BUT it produces this:



Reproducible: Always

Steps to Reproduce:
1.See code above
Actual Results:  


Expected Results:  


Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list