-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make JsonOutputFormatter use camel case by default #4283
Comments
/cc @JamesNK |
+1 for camelCase by default |
Word! |
makeJsonCamelCaseAgain |
While we're at it; can we propose to set I assume that a high percentage of JSON returned from an API is consumed by JavaScript, where both It should also be no problem if the consumer is using Newtonsoft.Json, where |
@khellang create new issue if you want, let's keep this one focused just on camelCase |
Go Go Go just do it 😃 |
+3.14 :) And more :) |
As a compliment to #1765 makes perfect sense. cc/ @danroth27 |
+1 |
1 similar comment
+1 |
Take my vote |
Thanks all. Make sure you use the upvote feature if you +1d |
I see +1's are alive and well even after github reactions. Camel case makes sense when consuming JSON from JavaScript but I think JSON and MVC is more than just JavaScript. I think the default is better left taking what the user has defined (camel case everywhere would override expicit names specified with |
Mobile version of page does not allow to add reaction. |
If you do want to make this change then I think global naming needs a better feature in Json.NET. There are some problems with A better solution would be adding some sort of |
Where do I submit my PR for this? Make it so! |
@JamesNK that would be awesome, we default to camelCase in elasticsearch's .NET client but need some hoops to make sure verbatim properties work e.g dictionaries/json properties/client mappings And A more directly supported approach would be awesome! |
+1 |
Yay! we're like everyone else now! |
@rynowak - tell me the truth. Was the ❤️ for the change, or for the amazing MS Paint job? |
Ah, one issue is INamingStrategy isn't in 8.0.4-beta1. It is sitting in its own branch. |
- JSON now serialized with camel case - another part of fix for aspnet/Mvc#4283
- #4283 - update `JsonSerializerSettingsProvider` to choose the `CamelCaseNamingStrategy`
- #4283 - update `JsonSerializerSettingsProvider` to choose the `CamelCaseNamingStrategy`
I suggest you add a couple of unit tests for behavour of serializing dictionary keys (e.g. IDictionary<string, string>) and properties with JsonProperty("name") to make sure you're happy with how those serialize. The default constructor for CamelCaseNamingStrategy won't camel case dictionary keys or override explicitly specified names but some tests would verify that MVC expects that camel casing works that way. |
So... if I have existing ASP.NET 4.6 code that reads/writes JSON the default way it's been for many years now, and that JSON is stored as a string, and I want to use .NET Core to read it... will I be able to just read the existing data as-is, or do I have to do a convert-to-camel-case on my data as part of the migration to get it to deserialize into the .NET Core objects? Or is there a PascalCaseNamingStrategy I could use? |
@SBArbeit I believe you can clear out the naming strategy and that'll work. Or, it might just work anyway, depending on the exact scenario (not everything is always case-sensitive). |
When deserializing Json.NET will first attempt to match a property exactly, e.g. "firstName" in JSON will attempt to be deserialize to a .NET property called You can set NamingStrategy to null. |
@JamesNK @rynowak [cameCase] //should provide by json.net
public class Persion
{
public int Id { get; set; }
public string Name { get; set; }
} I think this will give more controllable . Json is not javascript And it not only use by javascript, it's a data formate now use in many languages . // this is a line in project.json
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final", will be "microsoft.AspNetCore.Mvc": "1.0.0-rc2-final", Please rethink about this change. |
There is that feature.
All those other languages are either camel casing or snake casing. It's just a default and it is one line to turn it off. |
Beyond just casing, I find |
@JamesNK Can We use |
Have we consulted the Xamarin and enterprise folks on this issue, yet? 😉 So to summarize:
Please help me see what I am missing here that makes me say that this is inconsistent and fosters (more like festers) context-switching between two the areas of concern. Maybe I found it here:
Thank you for saving my sanity @JamesNK. 😄 That's encouraging. The problem is that C# increasingly appears to be the "odd duck" by holding onto PascalCase as its established default naming convention, and it seems that more and more tech -- MSFT tech, even and this is a good example -- is moving away from it. This is especially so when you view the Azure code samples that are coming out. It seems like everything BUT C# is camelCase. But alas, we still use C# and hinge upon it for our solutions, generally speaking. I am all for consistency, but if you are building your application in C#, you simply lose that consistency by deviating from its defaults. FWIW, I have always felt this way. I was not (and am not) a fan of .NET Configuration's (app/web.config) approach, either. BTW, this is (yet another reason) why Xaml rocks so hard, as it has 100% parity to what it serializes/deserializes. 😛 The class definition IS the schema. |
HTTP is not tied to a particular runtime stack, it is not a serialization
|
Yet we have chosen to tightly-couple our entire design and infrastructure upon HTTP, which seems a little incongruous. Why must we know of HTTP within our code? If there is any abstraction to be done, it would seem that designing a protocol-agnostic system is the place to start. As great as HTTP is with its natural-lending verb and design elements, I still cringe whenever I see anything that requires it (or its concepts) to be in code. I have always found it strange that no one questions why we are coupling design with a protocol. But I digress. I do appreciate your explanation @glennblock. Thank you for taking the time to do so. I realize I am in the minority here, and I am not looking to reverse community consensus (ok, maybe a little 😄 ). The best I can hope for is to point out the solution inconsistency we have introduced here from a .NET perspective. And although I appreciate the aim of playing along nicely with others going forward, we have done so at a cost towards what has gotten us here to date. |
yeah just do it and let the rest of the world waste their time searching for a solution. Great!! |
It's not the 1990s, everyone expects their JSON to be camel case :-)
Can we get this to be the default so we don't have to do this: https://gist.github.com/shahiddev/e82fea1c85d5e3faa710
I am curious if anyone actually desires pascal case to even be an option.
The text was updated successfully, but these errors were encountered: