gpt4 book ai didi

java - GAE 应用程序将 Long 序列化为字符串。如何改变呢?

转载 作者:太空宇宙 更新时间:2023-11-04 10:33:59 25 4
gpt4 key购买 nike

我有一个配置了 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;
}
}

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

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

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

最佳答案

来自: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();

关于java - GAE 应用程序将 Long 序列化为字符串。如何改变呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49678768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com