2

I am using Microsoft.AspNetCore.JsonPatch which I've added via NuGet from here and got stuck when trying to match my properties back on API-side.

Is there any way to preserve the camel-case naming of my properties when serializing/deserializing.

My simplified object:

public class MyObject
{
    public string MyCamelCaseProperty { get; set; }
}

When creating a JsonPatchDocument<MyObject> with the operation Replace I get the path /mycamelcaseproperty. But, on API-side I want to make some sort of switch-case by the path property (without the leading '/') like

var normalizedPath = operation.path.Replace("/", string.Empty)
switch(normalizedPath)
{
    case nameof(MyObject.MyCamelCaseProperty):
        // do replacement of the MyCamelCaseProperty property
        break;
}

The question is: Can the camel-case be preserved or do I have to find another way on how to match the property-names I have to do actions on? Any ideas would be greatly appreciated.

KingKerosin
  • 3,639
  • 4
  • 38
  • 77
  • Where is ´NormalizedPath´ defined ? I have search the Repo https://github.com/aspnet/JsonPatch but there the case preserving Path property is defined for JsonPatch operations. Perhaps in NoarmalizedPath is some kind of LowerCase logic defined. – Ralf Bönning Jan 09 '17 at 09:37
  • Sorry. The `NormalizedPath` is just the path-name without the leading '/' to just get the property-name. Will update my question – KingKerosin Jan 09 '17 at 09:39
  • @rboe: Seems like the version from nuget (1.1.0) is not the same as within aspnet.core, right? – KingKerosin Jan 09 '17 at 09:45

0 Answers0