[CSHARP-147] Cannot deserialize JSON with a nested class where the first property is a Guid Created: 12/Jan/11  Updated: 02/Apr/15  Resolved: 14/Jan/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 0.9
Fix Version/s: 0.11

Type: Bug Priority: Major - P3
Reporter: Bailey Ling Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

This occurs on today's git build (8d1d29365ebefea40d2c).

The problem only happens if the Guid is the first property of the nested type. If you swap the order of the guid and int for the Child class, it will work.

public class Parent
{
public Child Child

{ get; set; }
}

public class Child
{
public Guid Id { get; set; }

public int A

{ get; set; }

}

[Test]
public void Test()
{
var p = new Parent

{ Child = new Child() }

;
p.Child.A = 1;
var json = p.ToJson();
BsonSerializer.Deserialize<Parent>(json); // throws Unexpected element exception
}



 Comments   
Comment by Robert Stam [ 14/Jan/11 ]

It was not reading the closing "}" of the extended JSON representation for binary data.

Comment by Bailey Ling [ 12/Jan/11 ]

It appears that it doesn't have to be the first property, but there cannot be anything following the guid.

Generated at Wed Feb 07 21:35:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.