2

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.

Jigar
  • 129
  • 5
iuiz
  • 957
  • 1
  • 10
  • 23
  • did you ever figure this out? i'm running into the same problem trying to deserialize Box2D shapes from JSON – sean christe Oct 16 '12 at 03:25
  • No, i think PlayN currently lacks many important features, due to the missing reflection capabilities of JavaScript. I started to implement a toJson method for every DTO on my client. At least on the server you can use something better. Look at this answer: http://stackoverflow.com/a/9071833/515085 – iuiz Oct 21 '12 at 13:48
  • For communication between client and server I use the same PlayN.json() classes since I already had to write client side code to be able to read the json, especially giving how easy of a task it is. – Keldon Alleyne Dec 15 '12 at 00:19

0 Answers0