On Tuesday, May 9, 2017 at 12:08:12 PM UTC+2, Marcin Okraszewski wrote:
>
> In short I would like JS arrays to be visible in GWT as a List and objects 
> parsed from JSON also as a Map. 
>
> Maybe I'll try one more time to explain what we have. We share model 
> between server and GWT in form of java interfaces. Those interfaces are 
> declared as return types of Jersey services, which serve instances of those 
> interfaces. GWT uses exactly the same interfaces and handles them with 
> AutoBeans. It works quite well, but there are two issues. First issue is 
> that occasionally we need to pass some part of the data to JS. More often 
> than not, it is a list or contains a list. As a result, we need to 
> repackage it, as GWT objects are not understood by JS. Now we plan to 
> leverage more JS, so we will have to deal with this problem more often. 
> Second issue is that AutoBeans turned out to be inefficient in larger 
> scale, as the generated code is roughly 50% of our written code.
>
> So, we came up with following idea: let’s keep shared interfaces, just 
> annotate them with @JsType(native=true). Then use regular browser’s JSON 
> parser and cast parsed object into model interface with @JsType. It works 
> like charm for simple objects, but not for collections - List is being 
> parsed as an JS array; Map is nothing else but just regular object. 
> Dropping support for java collections, would be very expensive, and would 
> require heavy refactoring, as the app is big (over 0.5 million Java lines 
> in GWT + affected server parts). I thought there could be a way to tell 
> JsInterop that specific field is backed by a plain array (or list) and an 
> object (for map).
>

How about using the 'reviver' argument of JSON.parse() to copy/wrap arrays 
into lists? (would be harder to detect those objets that you want into maps 
though; the "reviver" could probably be generated from your interfaces to 
match on the key name though – this is something I've been thinking about 
for a few days actually, I really need to put my thoughts together in a 
gist or a message to this list)
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
 

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/642a383f-ce8a-4224-b778-9bcecf6dbe44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to