https://bugzilla.novell.com/show_bug.cgi?id=639381
https://bugzilla.novell.com/show_bug.cgi?id=639381#c0 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: [email protected] ReportedBy: [email protected] QAContact: [email protected] 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 JSONTestDisplay.cs public partial class JSONTestDisplay : Form { protected List<Type> _knownTypes = new List<Type>(); protected DataContractJsonSerializer _json; protected Encoding _encoding = new ASCIIEncoding(); public JSONTestDisplay() { InitializeComponent(); } 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) { _knownTypes.Add(typeof(Noddy)); _json = new DataContractJsonSerializer(typeof(object),_knownTypes); } private void cmdDeserialize_Click(object sender, EventArgs e) { using (MemoryStream memoryStream = new MemoryStream(_encoding.GetBytes(txtJSON.Text))) { memoryStream.Position = 0; object outObject = _json.ReadObject(memoryStream); MessageBox.Show("Success"); } } } Noddy.cs [DataContract] public class Noddy { /// <summary> /// Constrcutor /// </summary> public Noddy() { } [DataMember] public int Id { get; set; } [DataMember] public string Name { get; set; } [DataMember] public int Age { get; set; } [DataMember] public int Shoesize { get; set; } } The output from the above should produce: {"__type":"Noddy:#JSONTest","Age":12,"Id":1,"Name":"Test","Shoesize":34} BUT it produces this: {"Age":12,"Id":1,"Name":"Test","Shoesize":34} Help! Reproducible: Always Steps to Reproduce: 1.See code above 2. 3. Actual Results: {"Age":12,"Id":1,"Name":"Test","Shoesize":34} Expected Results: {"__type":"Noddy:#JSONTest","Age":12,"Id":1,"Name":"Test","Shoesize":34} -- 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. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
