ra0o0f / arangoclient.net

ArangoDB .NET Client with LINQ support
Apache License 2.0
99 stars 37 forks source link

JsonProperty - PropertyName not being used during insert #98

Open TimF2004 opened 6 years ago

TimF2004 commented 6 years ago

When I insert a object into my collection, the JSONProperty.PropertyName is not used when saving the document to my collection.

I am using the Nuget GeoJSON.Net library for my objects and this library uses custom converters for Serialization/Deserialization. All of the classes in the library are decorated so that then serialized attributes conform to the GeoJSON spec.

As an example, one of the classes has a property called BoundingBoxes and this property decorated with a JSONProperty.PropertyName = "bbox". When records are inserted into my collection, they are saved using the "BoundingBoxes" label instead of the bbox label.

the class property looks like this

[JsonProperty(PropertyName = "bbox")]
public double[] BoundingBoxes { get; set; }

I've tried to add a CustomConverter to the db object but when i do, i get a "self referencing loop detected" error.

db.Setting.Serialization.Converters.Add(new GeoJSON.Net.Converters.GeoJsonConverter());

Is ignoring the JSONProperty.PropertyName the intended behavior, or am I doing something wrong in my code? if the issue is on my end, do you have any suggestions on how to get PropertyNames used during the serialization?

Thanks, Tim

Edit 02/09/2018

I think i found the issue... in the DocumentContractResolver class there is a call to CreateProperties, in this call there is a call that uses the UnderlyingPropertyName

p.PropertyName = sharedSetting.Collection.ResolvePropertyName(type, p.UnderlyingName);

this is causing the Code to ignore the PropertyName that is assigned in the through the JsonProperty Attribute.

I have forked the master branch to add a new property to the sharedSettings.serialization as well as a new check in the Change property settings the code snippet is like this:


// this change allows the JsonProperty.PropertyName to be used instead of the Object.PropertyName
if (!sharedSetting.Serialization.UseUnderlyingPropertyName && p.PropertyName != p.UnderlyingName) {
  documentProperty.PropertyName = p.PropertyName;
}

This resolves my issue, but I'm not sure if it is the correct way to solve the problem. does anyone else have any ideas?