How bad is it using camelCasing instead of PascalCasing for varialbe method and member in C #

We use Java for backend programming and C # for application programming.

We communicate with the server using json serialization like NewtonJson (C #) and Gson (Java)

In the Java world, the program guide uses camelCasing , in which case the username should be userName

, but according to the C # guide, they use PascalCasing when it should be userName

in C #.

So when using json deserialization and serialization on the app side or server side it will mess up.

So we are planning to change the agreement of the application parties' program to camelCase.

Or is there anyway you can fix this problem? Or that your team is considering this issue?

+3


source to share


1 answer


There are several options here:

"Smoothing"

Any decent structure should allow you to use annotations to use a different name in the JSON representation and the actual field names!

Using gson for example:

public class Example {
  @SerializedName("lisp-style-name")
  private String someField.... 

      



In other words: make sure all JSON field names follow this convention - then you are not dependent on the main programming language.

The big drawback, of course, is to annotate every field - perhaps even on both sides . On the other hand, the above is really clear - you understand what should happen just by looking at your data class declaration.

Support for custom names

Both gson and NewtonJson support policies . So instead of doing the mapping manually, you can instruct the structure to translate field names.

See here how to do it using gson; for C # you have a duplicate question.

+1


source







All Articles