Closed corock closed 3 months ago
I will resolve it myself and close the issue.
I found that when using
GsonBuilder
, you cansetFieldNamingStrategy()
orsetFieldNamingPolicy()
through method chaining
Alternatively you can annotate the fields with @SerializedName
. That might be easier if you just want to change the name of a few fields.
Gson version
2.9.1
Java / Android version
Java 11
Used tools
Description
When calling the specific API method named
foo
, there is an issue with serializing the returned typeFooResponse
. The problem occurs when applying naming conventions immediately to the first and second words. This phenomenon does not occur at index 2 or higher, but it specifically occurs at index 0 and 1.Upon further investigation, I found that when using
GsonBuilder
, you cansetFieldNamingStrategy()
orsetFieldNamingPolicy()
through method chaining. It would be helpful if you could provide some ideas on whether this method can be used to solve the issue described below.Expected behavior
Actual behavior
Reproduction steps
Precondition
Operation Steps
FooResponse
. When naming the properties, name them in camel case directly for index 0 and 1, such asxandYType
(When serialization occurs, it should appear as xAnd... in the JSON response value).build.gradle
FooConfig.java
Exception stack trace
It is not an exception, but the lies with proper capitalization mapping. The client-side cannot receive the appropriate response value due to this issue.