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.
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
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?
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
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 resolves my issue, but I'm not sure if it is the correct way to solve the problem. does anyone else have any ideas?