The following example shows that json deserialization ignores the case of the setters, and deserializes two different fields that differ only in case to the same setter.
I stepped through in a debugger, and I think the issue is this logic that setups up a FieldInfo for deserialization ignores case:
|
if (Ascii.toLowerCase(method.getName()).equals("set" + Ascii.toLowerCase(field.getName())) |
|
&& method.getParameterTypes().length == 1) { |
That logic was added as part of ff93479
Repro
With com.google.http-client:google-http-client-gson:1.28.0
Serialized: {"passCode":"pass1","passcode":"pass2"}
{"passCode":"pass2"}
With com.google.http-client:google-http-client-gson:1.27.0
Serialized: {"passCode":"pass1","passcode":"pass2"}
{"passCode":"pass1","passcode":"pass2"}
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.Key;
import java.io.StringReader;
import java.io.StringWriter;
public class Repro {
public static final class Data extends GenericJson {
@Key String passcode;
@Key String passCode;
public String getPasscode() {
return passcode;
}
public Data setPasscode(String passcode) {
this.passcode = passcode;
return this;
}
public String getPassCode() {
return passCode;
}
public Data setPassCode(String passCode) {
this.passCode = passCode;
return this;
}
}
public static void main(String[] args) throws Exception {
String serialized;
{
Data c = new Data().setPassCode("pass1").setPasscode("pass2");
StringWriter writer = new StringWriter();
new GsonFactory().createJsonGenerator(writer).serialize(c);
serialized = writer.toString();
}
System.out.println("Serialized: " + serialized);
Data parsedData =
new GsonFactory()
.createJsonObjectParser()
.parseAndClose(new StringReader(serialized), Data.class);
System.out.println(parsedData);
}
}
The following example shows that json deserialization ignores the case of the setters, and deserializes two different fields that differ only in case to the same setter.
I stepped through in a debugger, and I think the issue is this logic that setups up a
FieldInfofor deserialization ignores case:google-http-java-client/google-http-client/src/main/java/com/google/api/client/util/FieldInfo.java
Lines 140 to 141 in 84216c5
That logic was added as part of ff93479
Repro
With
com.google.http-client:google-http-client-gson:1.28.0With
com.google.http-client:google-http-client-gson:1.27.0