如何在 PlayN 中将 POJO 转换为 JSON?
我想将包含 json 内容的字符串发送到 REST 服务。如何将简单的 POJO 转换为 json 字符串?通常我会使用 Gson 来执行此操作:
我想要转换的类:
public class UserMdl {
String name;
String pwHash;
//Constructur, getter and setter....
}
以及执行此操作的代码:
UserMdl userMd = new UserMdl("name", "pwHash");
Gson gson = new Gson();
String json = gson.toJson(userMdl);
但是我无法让 gson 在 HTML 构建中与 PlayN 一起使用。它仅适用于 Java 构建。我不知道如何使用 PlayN.json() 的东西来做到这一点。
I want to send a string with json content to a REST service. How can I convert a simple POJO to a json string? Normaly I would use Gson to do this:
My class that I want to convert:
public class UserMdl {
String name;
String pwHash;
//Constructur, getter and setter....
}
And my code to do this:
UserMdl userMd = new UserMdl("name", "pwHash");
Gson gson = new Gson();
String json = gson.toJson(userMdl);
However I cannot get gson to work with PlayN in the HTML build. It only works in the Java build. And I cannot figure out how to do this with the PlayN.json() stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论