Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-482

JSON serialized ObjectID can't be deserialized back

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.4.2
    • Component/s: None
    • Labels:
    • Environment:
      .Net 4.5, Windows 7, C# driver 1.4.2

      Here is a small console application to reproduce the bug

      namespace ConsoleApplication1
      {
      class Program
      {
      class A
      {
      public ObjectId Id

      { get; set; }
      public string Name { get; set; }

      public int counter

      { get; set; }

      }
      static void Main(string[] args)
      {
      var a = new A()

      { Id = ObjectId.GenerateNewId(), Name = "Test1", counter = 1 }

      ;
      JavaScriptSerializer json = new JavaScriptSerializer();
      var s = json.Serialize(a);
      var b = json.Deserialize<A>(s);
      }
      }
      }

      a and b are different. b does match Name and counter field but Id are different.

      A.Id = 4fc68f495669bd1ba000e831
      B.Id = 000000000000000000000000

      s = {\"Id\":

      {\"Timestamp\":1338412873,\"Machine\":5663165,\"Pid\":7072,\"Increment\":59441,\"CreationTime\":\"\\/Date(1338412873000)\\/\"}

      ,\"Name\":\"Test1\",\"counter\":1}

      FYI, python serialized ObjectId looks like this:
      >>> json.dumps(d, default=json_util.default)

      '{"_id":

      {"$oid": "4fc68f495669bd1ba000e831"}

      , "Name": "Test1", "counter":1}'

      Do you think JSON serialized ObjectId can match between drivers? (GUID JSON output are also different between drivers)

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            swell Swell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: