I have tried something like: 

@JsType(namespace=GLOBAL)
public class Record {
String id;
String date;
String data;
public Record() {
}
}

As mentioned above, I created a JsInterop wrapper for the JSON class in 
javascript :

@JsType(isNative=true, namespace=GLOBAL)
public class JSON {
public native static String stringify(Object obj);

}

After calling : 

  Record record = new Record();
       record.id = "1";
       record.date = "20";
       record.data = "30";

GWT.log(JSON.stringify(record));

I got : 

{"id_1_g$":"1","date_1_g$":"20","data_1_g$":"30"}

I am not sure why does GWT adds _1_g$ to all properties. the solution is to 
annotate properties with @JsProperty(name="property name") 





Le jeudi 18 août 2016 09:33:37 UTC+2, Max Fromberger a écrit :
>
> Hello everybody,
>
> First of all a big THANKS to everyone involved in developing and 
> supporting GWT.
>
> please correct me wherever I am wrong:
>
> In the past you used JsonUtils.safeEval() to create a JavaScriptObject 
> from a JSON String. As i understand it, jsinterop annotations on classes 
> not extending JavaScriptObject are now preferred over JavaScriptObjects.
>
> What is the recommended, future-proof way of having a server-client common 
> class (i.e. package "shared") that can be:
>
> - created and accessed in a JVM servlet
> - created and accessed from the client end
> - serialized to JSON / deserialized from JSON to the specific class on the 
> server (e.g. using GSON)
> - serialized to JSON / deserialized from JSON to the specific class on the 
> client
>
> Background: Using WebSocket Servers to bidirectionally transfer JSONified 
> objects. No GWT-RPC involved.
> Trying to avoid duplicate environment specific classes, boilerplate code 
> etc.
>
> Thanks for every clue and please overlook me not having a native English 
> interface. ;)
>
>
>
> kind regards,
> max
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to