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

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Mar 22 21:37:27 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=639381

https://bugzilla.novell.com/show_bug.cgi?id=639381#c1


Adam Fletcher <fletcham at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fletcham at gmail.com

--- Comment #1 from Adam Fletcher <fletcham at gmail.com> 2011-03-23 01:37:26 UTC ---
I am experiencing the same situation with my code.  Running identical code on a
windows machine (Windows 7) produces a different result than when it is run on
a Mac (Mac OS X 10.6.5)

On Windows 7 using mono/.net 3.5 it gives me this result: 

[{"Suit":0},{"Suit":1},{"Suit":2}] 

On Mac OS X 10.6.5 using mono/.net 3.5 it gives me this result: 

[{"__type":"Card:#JsonTest","Suit":0},{"__type":"Card:#JsonTest","Suit":1},{"__type":"Card:#JsonTest","Suit":2}]

Listed below is a console application that can be run to show the results
listed above.  In order to run this you need to include two references:
System.Runtime.Serialization and System.ServiceModel.Web.

using System; 
using System.Collections.Generic; 
using System.Runtime.Serialization.Json; 
using System.IO; 
using System.Text; 

namespace JsonTest 
{ 
        class MainClass 
        { 
                public static void Main(string[] args) 
                { 
                        Hand hand = new Hand(); 
                        hand.Add(new Card { Suit = 0 }); 
                        hand.Add(new Card { Suit = 1 }); 
                        hand.Add(new Card { Suit = 2 }); 

                        string json; 

                        DataContractJsonSerializer ser = new
DataContractJsonSerializer(hand.GetType()); 
                        using (MemoryStream ms = new MemoryStream()) 
                        { 
                                ser.WriteObject(ms, hand); 
                                json =
Encoding.Default.GetString(ms.ToArray()); 
                        } 

                        Console.WriteLine(json); 
                } 
        } 

        public class Card 
        { 
                public int Suit { get; set; } 
        } 

        public class Hand : List<Card>
        { 

        } 
}

-- 
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