We have some DTOs that we've previously been able to share among our middle tier C# models and the models we use for ES. I've seen ES 5.x documentation which shows that JsonProperty is allowed but w/ the internalization of Newtonsoft (or whatever parser you've chosen), I've discovered that I have to use Rename or Text on all my models which would be fine except where I want directly share them as I explained above. Should JsonProperty still be supported as before in NEST 6.0? I just discovered this because, for some of our indexes, we use strict mappings. Anyway, the DTOs are in a place where I'd prefer not to expose the Nest library.
Actually, I think this is a layering problem anyway. If anyone has any other suggestions, that's great but I think I'm going to solve this problem by just moving the DTO to our search service abstraction and having all parties consume it from there. However, I'll leave this open to confirm continued support for JsonProperty w/ Nest or not.
I just downloaded the GA and I now see that Rename is gone ... please advise. I was following what was suggested here: NEST 6.0 Beta: JsonProperty attribute not working?. I see that Text is available but what about non-text fields?
@tdoman - Rename() has been renamed to PropertyName() to tie it in with the name of the attribute.
Thanks @codebrain, can you also comment on my original question on JsonProperty? In other words, is PropertyName required now or should I still be able to use JsonProperty? My experience has been confusing cuz it seems like I have been able to some places and others not. At any rate, I can try out PropertyName as soon as I get a resolution for #3070, most especially ConcreteTypeSelector, that's an absolute blocker for me.
You won't be able to use JsonPropertyAttribute @tdoman, since it is a Json.NET type and the NEST assembly will not know what this is; the internalized Json.NET is re-namespaced from Newtonsoft.Json to Nest.Json, so the attribute that NEST knows about is Nest.Json.JsonPropertyAttribute and its internal.
PropertyNameAttribute exposes a hook to use to control the serialized property names of your types within NEST 6.x, similar to how you would have used JsonPropertyAttribute in NEST 5.x. We could have considered making Nest.Json.JsonPropertyAttribute a public type, but I think this is perhaps more confusing, especially if you're using NEST in a project alongside Json.NET!
Yep, that makes sense, thanks for the clarification @russcam.
If I understand correctly, if I use the separate Nest.JsonNetSerializer package (as in var connectionSettings = new ConnectionSettings(pool, sourceSerializer: JsonNetSerializer.Default)), my JsonPropery attributes would continue to work, right?
@jonyadamit yes that is correct.
You won't be able to use
JsonPropertyAttribute@tdoman, since it is a Json.NET type and the NEST assembly will not know what this is; the internalized Json.NET is re-namespaced from Newtonsoft.Json to Nest.Json, so the attribute that NEST knows about isNest.Json.JsonPropertyAttributeand its internal.
PropertyNameAttributeexposes a hook to use to control the serialized property names of your types within NEST 6.x, similar to how you would have usedJsonPropertyAttributein NEST 5.x. We could have considered makingNest.Json.JsonPropertyAttributea public type, but I think this is perhaps more confusing, especially if you're using NEST in a project alongside Json.NET!
The PropertyNameAttribute helped a lot for me. Thanks @russcam
As @jonyadamit described, I did the following cuz I also needed to configure the serializer settings:
var settings = new ConnectionSettings(pool, sourceSerializer: (b, s) => new JsonNetSerializer(
b, s,
() => new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }))
...
In the haze of time, I can't remember why this allowed me to use JsonProperty everywhere since it's still a NEST serializer instance but that was the trick that enabled me to not expose NEST (ie. PropertyName) in other layers of my code that use the same POCO's.
Most helpful comment
@jonyadamit yes that is correct.