Open gabrielbutron opened 5 years ago
Hi,
Are you calling the AddHypermediaFormatters extension method to configure? If so this uses the DasherizedFieldNamingStrategy as its default;
But you can call one of the other methods that takes the IFieldNamingStrategy and pass in the DefaultFieldNamingStrategy.Instance instead.
Thanks, Cain.
Looking at your code, gave me the idea to use options.JsonApiSerializerOptions.FieldNamingStrategy
instead of options.FieldNamingStrategy
and it worked.
services .AddMvc() .AddHypermediaFormatters( options => { options.ContractResolver = contractResolver; options.JsonApiSerializerOptions.FieldNamingStrategy = DasherizedFieldNamingStrategy.Instance; }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
I was confused because in the example code it is using options.FieldNamingStrategy
:
https://github.com/cosullivan/Hypermedia/blob/master/Src/Hypermedia.Sample.AspNetCore/Startup.cs#L31
Not sure if this was intended and we want to change the code base or the example :)
I just had a look over that configuration code and yes that its quite confusing.
The IFieldNamingStrategy and IContractResolver can be set in two places and I can't remember why that is the case now. I will have a look and see if I can refactor that so its cleaner.
Thanks, Cain.
Hi, I have problems formatting attribute names in .NET Core 2.2 using Hypermedia. Below is an example of the result of a formatted object:
{ "data":{ "type":"products", "id":"1", "attributes":{ "Name":"ProductA", "Price":10, "Description":"descripcion 1", "OwnerName": "OwnerA" } } }
As you see we have the attribute names with Capital letter ("Name" instead of "name"). Composite words are not dashed and also start with Capital letter ("OwnerName" instead of "owner-name").
I'm missing something? Thanks in advance.
Versions: .NET Core 2.2 Hypermedia 1.1.0 Hypermedia.JsonApi.AspNetCore 1.3.6