UnderScore or CamelCase
- Json String could be underscore(access_token) or camel(accessToken) form
- Mapping Json to Model(noramlly camelCase), need to specify Name Strategy if json property in a underscore format, otherwise will lost value(null)
- default mapping by name
for signle property, use annotation
@JsonProperty(value = "access_token") private String accessToken;
for globe setting, set ObejctMapper.PropertyNamingStrategy
- in practice, create a util class to custom jackson objectmapper, config its features, like serializer/deserializer, time format, name strategy, etc.
- Ref Doc: https://github.com/FasterXML/jackson-databind/wiki
@SerializedName(value = "access_token") private String accessToken;
globe way, setFieldNamingPolicy
Gson gson = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create();
- also could use util class
- Spring integrated JacksonJson as message coverter, so could use globe way to do once/everywhere.
- Gson normally used on special case, as some modern api not compitiable with it, as swagger, so cloud declear it in anywhere in-need, more domain design style.