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). I believe it was in plans with @JsConvert – see slides 67 – 69. https://docs.google.com/file/d/0ByS1wxINeBWjeGYxbkJpamxFZ28/edit Marcin On Tue, May 9, 2017 at 12:16 AM, 'Goktug Gokdogan' via GWT Contributors < [email protected]> wrote: > What do you mean exactly by "collection support in JsInterop"? From you > description I only understand that you want to keep using java collection > API for existing & server side code. > If you want use your JavaScript array/map instance from Java, you need an > adaptor; doesn't matter who provides. And sure you can do it yourself. > If you want use you Java collection from JavaScript, we already > jsinterop-enabled many collection APIs. > > On Mon, May 8, 2017 at 1:44 PM, Manuel Carrasco Moñino <[email protected]> > wrote: > >> If in your model is enough to have Collections/Lists based on ArrayList >> you can easily convert from JsArrays to ArrayLists and vice-versa by using >> a bit of JSNI since the ArrayList implementation in GWT relies on a >> javascript array. >> >> Take a look to this code used in the gwt-polymer-elements library (put >> attention to asList and asArrayList methods) >> >> https://github.com/manolo/gwt-api-generator/blob/master/lib/ >> com/vaadin/polymer/Polymer.java#L522 >> >> - Manolo >> >> >> On Mon, May 8, 2017 at 10:27 PM, Marcin Okraszewski <[email protected]> >> wrote: >> >>> Basically what we need it for is REST. Currently we use AutoBeans, but >>> we want to change it because we need to pass the model to JS too; secondly >>> AutoBeans generate a lot of code. We would like to still preserve shared >>> model with the server. So, JsInterop seems the most natural choice, except >>> it doesn't support collections. We mostly need List and Map. Switching to >>> JsInterop with replacing Lists with some JS array view would be quite an >>> effort. It would introduce that into our server logic too (by the shared >>> model). And and you could even use Java's for each loop, as native JsType >>> cannot extend non-JsType interfaces, so it could not extend Iterable (of >>> course adapter could be instantiated for every list you want to iterate). >>> Same for streams. >>> >>> Therefore we look for collection support in JsInterop, which was planned >>> for "phase 2". If that was in our reach, we could help in getting it. >>> >>> Marcin >>> >>> >>> On Monday, 8 May 2017 16:42:17 UTC+2, Ray Cromwell wrote: >>>> >>>> The adapter class adds overhead though and you need to convert into and >>>> out of it every time you pass it to JS. At that point you may as well use >>>> Java.util.List and write an adapter around JS array. >>>> >>>> >>>> On Mon, May 8, 2017 at 7:10 AM Jens <[email protected]> wrote: >>>> >>>>> IMHO if you want a JavaScript array, set, map behave the same as a >>>>> Java collection, so you can use it with other libraries, you should write >>>>> an adapter class that implements the Java API and operates internally on >>>>> the JavaScript data type. >>>>> >>>>> Basically do not rely on invisible magic. That could easily be >>>>> implemented as a 3rd party project. >>>>> >>>>> -- J. >>>>> >>>>> -- >>>>> 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-contributor >>>>> [email protected]. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/google-web-toolkit-contrib >>>>> utors/4d08f88c-ec88-4818-b778-3e0e247f2e7e%40googlegroups.com >>>>> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/4d08f88c-ec88-4818-b778-3e0e247f2e7e%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> -- >>> 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 [email protected] >>> . >>> To view this discussion on the web visit https://groups.google.com/d/ms >>> gid/google-web-toolkit-contributors/5e9868cd-35d6-4f48-81b8- >>> ef26ff791906%40googlegroups.com >>> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/5e9868cd-35d6-4f48-81b8-ef26ff791906%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- >> 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 [email protected]. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/google-web-toolkit-contributors/CAM28XAsesxqBxAS9Pjov% >> 3DfPqy_u2raCEmFWLsO6OZN%3DbDrcpqA%40mail.gmail.com >> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAM28XAsesxqBxAS9Pjov%3DfPqy_u2raCEmFWLsO6OZN%3DbDrcpqA%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to a topic in the > Google Groups "GWT Contributors" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/google-web-toolkit-contributors/Be2m_AnyL_g/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/google-web-toolkit-contributors/CAN%3DyUA1BE9gw6700%3Dia5Lq- > 2kOPahesOcX9SGcQSFvKrbO_mtw%40mail.gmail.com > <https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA1BE9gw6700%3Dia5Lq-2kOPahesOcX9SGcQSFvKrbO_mtw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAFrnd4-c9RF%2BjzF2LD4dSVjNzMpyr6a_%3D-0PceP%2BB0JxnLY18A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
