How do I convert a POJO to JSON in PlayN?

百般思念 提交于 2019-12-20 03:10:54

问题


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.

来源:https://stackoverflow.com/questions/9045455/how-do-i-convert-a-pojo-to-json-in-playn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!