-Fixed incorrect XML documentation
-Fixed writing JValue with readonly JsonConverters
This commit is contained in:
@@ -682,5 +682,40 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
Assert.AreEqual(expectedDate2, date2.Value);
|
Assert.AreEqual(expectedDate2, date2.Value);
|
||||||
}
|
}
|
||||||
#endif
|
#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:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[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);
|
}", json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json.Schema;
|
||||||
using Newtonsoft.Json.Utilities;
|
using Newtonsoft.Json.Utilities;
|
||||||
#if NET20
|
#if NET20
|
||||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||||
@@ -197,7 +198,7 @@ namespace Newtonsoft.Json.Converters
|
|||||||
.Select(a => a.Value)
|
.Select(a => a.Value)
|
||||||
.SingleOrDefault() ?? f.Name;
|
.SingleOrDefault() ?? f.Name;
|
||||||
#else
|
#else
|
||||||
n2 = f.Name;
|
n2 = f.Name;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
string s;
|
string s;
|
||||||
|
|||||||
@@ -616,7 +616,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
if (converters != null && converters.Length > 0 && _value != null)
|
if (converters != null && converters.Length > 0 && _value != null)
|
||||||
{
|
{
|
||||||
JsonConverter matchingConverter = JsonSerializer.GetMatchingConverter(converters, _value.GetType());
|
JsonConverter matchingConverter = JsonSerializer.GetMatchingConverter(converters, _value.GetType());
|
||||||
if (matchingConverter != null)
|
if (matchingConverter != null && matchingConverter.CanWrite)
|
||||||
{
|
{
|
||||||
matchingConverter.WriteJson(writer, _value, JsonSerializer.CreateDefault());
|
matchingConverter.WriteJson(writer, _value, JsonSerializer.CreateDefault());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -91,5 +91,5 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
|
|
||||||
[assembly: AssemblyVersion("4.5.0.0")]
|
[assembly: AssemblyVersion("4.5.0.0")]
|
||||||
[assembly: AssemblyFileVersion("5.0.8.16620")]
|
[assembly: AssemblyFileVersion("5.0.8.16801")]
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|||||||
@@ -119,31 +119,31 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
public JsonConverter Converter { get; set; }
|
public JsonConverter Converter { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the member converter.
|
/// Gets or sets the member converter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The member converter.</value>
|
/// <value>The member converter.</value>
|
||||||
public JsonConverter MemberConverter { get; set; }
|
public JsonConverter MemberConverter { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this <see cref="JsonProperty"/> is ignored.
|
/// Gets or sets a value indicating whether this <see cref="JsonProperty"/> is ignored.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value><c>true</c> if ignored; otherwise, <c>false</c>.</value>
|
/// <value><c>true</c> if ignored; otherwise, <c>false</c>.</value>
|
||||||
public bool Ignored { get; set; }
|
public bool Ignored { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this <see cref="JsonProperty"/> is readable.
|
/// Gets or sets a value indicating whether this <see cref="JsonProperty"/> is readable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value><c>true</c> if readable; otherwise, <c>false</c>.</value>
|
/// <value><c>true</c> if readable; otherwise, <c>false</c>.</value>
|
||||||
public bool Readable { get; set; }
|
public bool Readable { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this <see cref="JsonProperty"/> is writable.
|
/// Gets or sets a value indicating whether this <see cref="JsonProperty"/> is writable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value><c>true</c> if writable; otherwise, <c>false</c>.</value>
|
/// <value><c>true</c> if writable; otherwise, <c>false</c>.</value>
|
||||||
public bool Writable { get; set; }
|
public bool Writable { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this <see cref="JsonProperty"/> has a member attribute.
|
/// Gets or sets a value indicating whether this <see cref="JsonProperty"/> has a member attribute.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value><c>true</c> if has a member attribute; otherwise, <c>false</c>.</value>
|
/// <value><c>true</c> if has a member attribute; otherwise, <c>false</c>.</value>
|
||||||
public bool HasMemberAttribute { get; set; }
|
public bool HasMemberAttribute { get; set; }
|
||||||
@@ -171,7 +171,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this <see cref="JsonProperty"/> is required.
|
/// Gets or sets a value indicating whether this <see cref="JsonProperty"/> is required.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>A value indicating whether this <see cref="JsonProperty"/> is required.</value>
|
/// <value>A value indicating whether this <see cref="JsonProperty"/> is required.</value>
|
||||||
public Required Required
|
public Required Required
|
||||||
@@ -181,7 +181,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this property preserves object references.
|
/// Gets or sets a value indicating whether this property preserves object references.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// <c>true</c> if this instance is reference; otherwise, <c>false</c>.
|
/// <c>true</c> if this instance is reference; otherwise, <c>false</c>.
|
||||||
@@ -189,31 +189,31 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
public bool? IsReference { get; set; }
|
public bool? IsReference { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the property null value handling.
|
/// Gets or sets the property null value handling.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The null value handling.</value>
|
/// <value>The null value handling.</value>
|
||||||
public NullValueHandling? NullValueHandling { get; set; }
|
public NullValueHandling? NullValueHandling { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the property default value handling.
|
/// Gets or sets the property default value handling.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The default value handling.</value>
|
/// <value>The default value handling.</value>
|
||||||
public DefaultValueHandling? DefaultValueHandling { get; set; }
|
public DefaultValueHandling? DefaultValueHandling { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the property reference loop handling.
|
/// Gets or sets the property reference loop handling.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The reference loop handling.</value>
|
/// <value>The reference loop handling.</value>
|
||||||
public ReferenceLoopHandling? ReferenceLoopHandling { get; set; }
|
public ReferenceLoopHandling? ReferenceLoopHandling { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the property object creation handling.
|
/// Gets or sets the property object creation handling.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The object creation handling.</value>
|
/// <value>The object creation handling.</value>
|
||||||
public ObjectCreationHandling? ObjectCreationHandling { get; set; }
|
public ObjectCreationHandling? ObjectCreationHandling { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the type name handling.
|
/// Gets or sets or sets the type name handling.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The type name handling.</value>
|
/// <value>The type name handling.</value>
|
||||||
public TypeNameHandling? TypeNameHandling { get; set; }
|
public TypeNameHandling? TypeNameHandling { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user