-Fixed incorrect XML documentation

-Fixed writing JValue with readonly JsonConverters
This commit is contained in:
James Newton-King
2013-12-06 21:48:00 +13:00
parent 3e53808b1b
commit b96d9fb689
7 changed files with 91 additions and 16 deletions
@@ -682,5 +682,40 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(expectedDate2, date2.Value);
}
#endif
public class ReadOnlyStringConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotSupportedException();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return reader.Value + "!";
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(string);
}
public override bool CanWrite
{
get { return false; }
}
}
[Test]
public void ReadOnlyConverterTest()
{
JObject o = new JObject(new JProperty("name", "Hello World"));
string json = o.ToString(Formatting.Indented, new ReadOnlyStringConverter());
Assert.AreEqual(@"{
""name"": ""Hello World""
}", json);
}
}
}
@@ -75,4 +75,4 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
[assembly: AssemblyFileVersion("5.0.8.16620")]
[assembly: AssemblyFileVersion("5.0.8.16801")]
@@ -758,6 +758,45 @@ namespace Newtonsoft.Json.Tests.Schema
]
}
}
}", json);
}
[JsonConverter(typeof(StringEnumConverter))]
public enum SortTypeFlagAsString
{
No = 0,
Asc = 1,
Desc = -1
}
public class Y
{
public SortTypeFlagAsString y;
}
[Test]
public void GenerateSchemaWithStringEnum()
{
JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator();
JsonSchema schema = jsonSchemaGenerator.Generate(typeof(Y));
string json = schema.ToString();
// NOTE: This fails because the enum is serialized as an integer and not a string.
// NOTE: There should exist a way to serialize the enum as lowercase strings.
Assert.AreEqual(@"{
""type"": ""object"",
""properties"": {
""y"": {
""required"": true,
""type"": ""string"",
""enum"": [
""no"",
""asc"",
""desc""
]
}
}
}", json);
}
}