@SerializedName忽略

时间:2018-06-13 12:39:19

标签: java gson google-cloud-endpoints

我的Google云端点在帖子正文中收到一个对象,当将JSON转换为实际的Java对象时,大部分字段都是空的。似乎端点API没有考虑像@SerializedName

这样的gson注释
public class MyObject{

    @SerializedName("production_unit_ID")
    private Long productionUnitId;
    ...
    getters / setters

}

API:

    @ApiMethod(name = "puMyObject", httpMethod = "put", path = "putMyObject")
        public MyObject putWorkOrder(HttpServletRequest req, MyObject myobj) {

        myobj.getProductionUnitId(); // <-- null

在我的pom.xml中,我根据文档的要求添加了以下依赖项:

https://developers.google.com/api-client-library/java/google-http-java-client/app-engine

<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client</artifactId>
    <version>1.23.0</version>
</dependency>

<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client-gson</artifactId>
    <version>1.23.0</version>
</dependency>

1 个答案:

答案 0 :(得分:0)

端点并没有使用GSON。请改用此ApiResourceProperty

相关问题