faunadb-csharp icon indicating copy to clipboard operation
faunadb-csharp copied to clipboard

Change property resolution of To<TModel>() to align with Newtonsoft.Json convention

Open wingertge opened this issue 8 years ago • 6 comments

This is a feature request. JSON convention says field names should start lowercase, while C# Properties start with an uppercase letter. Newtonsoft.Json converts the casing when serializing/deserializing, the FaunaDB driver should do so as well. Right now I either have to lowercase my model properties, or uppercase JSON fields, due to the lack of conversion (neither of which is a satisfactory solution).

wingertge avatar Sep 07 '17 09:09 wingertge

Hi @wingertge, using the attribute FaunaField to rename the field didn't solve your problem or this is not a possibility?

marrony avatar Sep 08 '17 17:09 marrony

I didn't see that anywhere in the documentation so I didn't know about it. In general I find the documentation rather lacking, a simple list of functions with their signatures doesn't help all that much. Anyways, that would solve the issue. I still think it's odd that the To method doesn't do this by default though - especially since the driver already uses Newtonsoft.Json as a dependency.

wingertge avatar Sep 09 '17 15:09 wingertge

What documentation you're referring? We should take that into consideration to improve our docs for other users

marrony avatar Sep 11 '17 19:09 marrony

I'm talking about the docs available on the website. It doesn't really cover many of the common usecases. For example, deleting or updating a record based on a single index match is a pretty common usecase, but the only mention of delete/update is using a ref. I managed to somewhat figure it out with the Roslyn REPL and a local DB instance, but that kind of thing should be on the docs.

That's really the main issue I meant. It could use more documentation on common real life use cases.

wingertge avatar Sep 16 '17 14:09 wingertge

Thanks for the feedback! I'll file a ticket internally to make the serialization/deserialization behavior match Newtonsoft.Json conventions a bit closer. I'll leave this ticket open to keep you updated on the progress.

As far as the docs go:

  • Right now, you're absolutely right. There's a gap between the pure reference documentation and our tutorials, which are a bit higher level. We're working on improving the docs, but in the meantime, if you haven't already, drop into our Gitter chat (https://gitter.im/fauna/Lobby) with questions.

  • We should be publishing csharp specific API documentation. I'll file a ticket to make sure we publish these.

eaceaser avatar Sep 27 '17 01:09 eaceaser

The casing really is annoying. The driver expects the property name to match exactly the field name and in .NET, properties usually start with an uppercase. The workaround is simple, to use the FaunaField attribute with the proper casing... But this equally annoying and adds unnecessary clutter to the model. I think that the matching should be case-insensitive, like Newtonsoft.Json converter does by default (or System.Text.Json).

It also annoys me that I can't deserialize into a generic Dictionary<string, object - or haven't figured out how, yet.

goncalo-oliveira avatar Jul 01 '21 10:07 goncalo-oliveira