You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have a mapped property and am using a custom contract resolver, then the contract resolver can alter the mapped property.
EXPECTED: The mapped property is exactly what I specified.
using DragonDoor.Services.Misc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace DeserializeTest
{
class Program
{
static void Main()
{
var json = new JObject(new JProperty("hello", "world"));
var settings = new JsonSerializerSettings { ContractResolver = new CustomContractResolver() };
var a = JsonConvert.DeserializeObject<Test>(json.ToString(), settings);
}
}
public class Test
{
[JsonProperty("hello")]
public string FooBar { get; set; }
}
public class CustomContractResolver : DefaultContractResolver
{
protected override string ResolvePropertyName(string propertyName)
{
return propertyName + "_";
}
}
}
The issue here is that I want every property that doesn't have a JsonPropertyAttribute specified, to follow the custom contract. However, if I specify the attribute then that is exactly what it should use.
Real world example: I am using the SnakeCamelCaseContractResolver. It puts an underscore in between text and numbers. This is supposed to mimic how Rails serializes, so I don't want to change their implementation. So I figure I can just add JsonProperty("address1"), an instance where the 3rd party does not follow the norm. But the contract resolver keeps changing the property name to address_1. It seems like if I specify what property I want, I should get that property, right?
The text was updated successfully, but these errors were encountered:
If I have a mapped property and am using a custom contract resolver, then the contract resolver can alter the mapped property.
EXPECTED: The mapped property is exactly what I specified.
The issue here is that I want every property that doesn't have a
JsonPropertyAttribute
specified, to follow the custom contract. However, if I specify the attribute then that is exactly what it should use.Real world example: I am using the SnakeCamelCaseContractResolver. It puts an underscore in between text and numbers. This is supposed to mimic how Rails serializes, so I don't want to change their implementation. So I figure I can just add
JsonProperty("address1")
, an instance where the 3rd party does not follow the norm. But the contract resolver keeps changing the property name toaddress_1
. It seems like if I specify what property I want, I should get that property, right?The text was updated successfully, but these errors were encountered: