1

我有一个配置了 Cloud Endpoints Framework v2 和 Java 8 的 GAE 应用程序。它对于已经在那里定义的服务运行良好。

我有一种定义新服务的方法。看起来像这样:

@ApiMethod(httpMethod = "get", path = "/operations/mine")
public UserOperationsResponse getOperationsForUser(User user) {
    return operationsService.
        getOperationsByUserId(user.getUserId());
}

这是UserOperationsResponse类的设计:

public class UserOperationsResponse {
    private List<Long> items;

    public UserOperationsResponse() {
    }

    public UserOperationsResponse(List<Long> items) {
        this.items = items;
    }

    public List<Long> getItems() {
        return items;
    }
}

该方法按预期工作并检索数据。但是,当我去邮递员并测试服务时,我得到了以下响应:

{
    "items": [
        "4676209648599040"  // <-- string
    ]
}

如何在响应中获取数字数组而不是字符串数组?

4

1 回答 1

0

来自: https ://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/users/User.html#getFederatedIdentity--

java.lang.String    getUserId()

返回一个不透明的字符串,该字符串唯一地标识此 User 对象表示的用户。

我想你想要:

user.getKey().getId();
于 2018-04-05T20:41:53.617 回答