简体   繁体   中英

How to handle dots in json key fields, while using retrofit?

I am just simply trying to use retrofit to perform my rest api calls. The issue that I am facing is that when parsing the json, some of the key fields contain dots. For example:

{ "data": { "name.first": "first name"} }

Is it possible to configure Retrofit (or GsonConverter) to be able to handle this and how do I go about doing so?

This is neither Retrofit nor the GsonConverter's responsibility but rather Gson which sits underneath doing the actual JSON (de)serialization.

You can use Gson's @SerializedName annotation to work around names which cannot be represented in Java:

@SerializedName("name.first")
public final String firstName;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM