-Fixed bugs and made improvements to help
This commit is contained in:
@@ -132,6 +132,52 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// </root>
|
||||
#endregion
|
||||
}
|
||||
|
||||
public void ForceJsonArray()
|
||||
{
|
||||
#region ForceJsonArray
|
||||
string xml = @"<person id='1'>
|
||||
<name>Alan</name>
|
||||
<url>http://www.google.com</url>
|
||||
<role>Admin1</role>
|
||||
</person>";
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xml);
|
||||
|
||||
string json = JsonConvert.SerializeXmlNode(doc);
|
||||
//{
|
||||
// "person": {
|
||||
// "@id": "1",
|
||||
// "name": "Alan",
|
||||
// "url": "http://www.google.com",
|
||||
// "role": "Admin1"
|
||||
// }
|
||||
//}
|
||||
|
||||
xml = @"<person xmlns:json='http://james.newtonking.com/projects/json' id='1'>
|
||||
<name>Alan</name>
|
||||
<url>http://www.google.com</url>
|
||||
<role json:Array='true'>Admin</role>
|
||||
</person>";
|
||||
|
||||
doc = new XmlDocument();
|
||||
doc.LoadXml(xml);
|
||||
|
||||
json = JsonConvert.SerializeXmlNode(doc);
|
||||
//{
|
||||
// "person": {
|
||||
// "@id": "1",
|
||||
// "name": "Alan",
|
||||
// "url": "http://www.google.com",
|
||||
// "role": [
|
||||
// "Admin"
|
||||
// ]
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -118,58 +118,58 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SerializationCallbacksObject
|
||||
public class SerializationEventTestObject
|
||||
{
|
||||
// 2222
|
||||
// This member is serialized and deserialized with no change.
|
||||
public int Member1 { get; set; }
|
||||
#region SerializationCallbacksObject
|
||||
public class SerializationEventTestObject
|
||||
{
|
||||
// 2222
|
||||
// This member is serialized and deserialized with no change.
|
||||
public int Member1 { get; set; }
|
||||
|
||||
// The value of this field is set and reset during and
|
||||
// after serialization.
|
||||
public string Member2 { get; set; }
|
||||
// The value of this field is set and reset during and
|
||||
// after serialization.
|
||||
public string Member2 { get; set; }
|
||||
|
||||
// This field is not serialized. The OnDeserializedAttribute
|
||||
// is used to set the member value after serialization.
|
||||
[JsonIgnore]
|
||||
public string Member3 { get; set; }
|
||||
// This field is not serialized. The OnDeserializedAttribute
|
||||
// is used to set the member value after serialization.
|
||||
[JsonIgnore]
|
||||
public string Member3 { get; set; }
|
||||
|
||||
// This field is set to null, but populated after deserialization.
|
||||
public string Member4 { get; set; }
|
||||
// This field is set to null, but populated after deserialization.
|
||||
public string Member4 { get; set; }
|
||||
|
||||
public SerializationEventTestObject()
|
||||
{
|
||||
Member1 = 11;
|
||||
Member2 = "Hello World!";
|
||||
Member3 = "This is a nonserialized value";
|
||||
Member4 = null;
|
||||
}
|
||||
public SerializationEventTestObject()
|
||||
{
|
||||
Member1 = 11;
|
||||
Member2 = "Hello World!";
|
||||
Member3 = "This is a nonserialized value";
|
||||
Member4 = null;
|
||||
}
|
||||
|
||||
[OnSerializing]
|
||||
internal void OnSerializingMethod(StreamingContext context)
|
||||
{
|
||||
Member2 = "This value went into the data file during serialization.";
|
||||
}
|
||||
[OnSerializing]
|
||||
internal void OnSerializingMethod(StreamingContext context)
|
||||
{
|
||||
Member2 = "This value went into the data file during serialization.";
|
||||
}
|
||||
|
||||
[OnSerialized]
|
||||
internal void OnSerializedMethod(StreamingContext context)
|
||||
{
|
||||
Member2 = "This value was reset after serialization.";
|
||||
}
|
||||
[OnSerialized]
|
||||
internal void OnSerializedMethod(StreamingContext context)
|
||||
{
|
||||
Member2 = "This value was reset after serialization.";
|
||||
}
|
||||
|
||||
[OnDeserializing]
|
||||
internal void OnDeserializingMethod(StreamingContext context)
|
||||
{
|
||||
Member3 = "This value was set during deserialization";
|
||||
}
|
||||
[OnDeserializing]
|
||||
internal void OnDeserializingMethod(StreamingContext context)
|
||||
{
|
||||
Member3 = "This value was set during deserialization";
|
||||
}
|
||||
|
||||
[OnDeserialized]
|
||||
internal void OnDeserializedMethod(StreamingContext context)
|
||||
{
|
||||
Member4 = "This value was set after deserialization.";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
[OnDeserialized]
|
||||
internal void OnDeserializedMethod(StreamingContext context)
|
||||
{
|
||||
Member4 = "This value was set after deserialization.";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void SerializationCallbacksExample()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user