How do I convert a POJO to JSON in PlayN?

2019-02-27 12:52发布

问题:

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.

标签: json playn