> When you think about it, other Java APIs (jaxb, jpa, Jackson) do go the
> extra mile to accommodate Java collections
Well kind of bad comparison right? These Java APIs either
serialize/deserialize based on a defined principle or stay in Java land
anyways.
> , and the example above looks like can be exported to js object (could use
> a helper annotation @JsX or two).
You don't "export" Java to JS but instead you consume JS using Java. That
means you would need to have a class that implements the Map interface and
takes a JS map as constructor parameter. Then you can implement the Java
API on top of the JavaScript API. In some cases you can simply delegate to
the JS API, in some cases you can't.
But thats something JsInterop does not do, however nobody stops you from
having something like
@JsType(native = true)
class JsArray<T> {
// ...get / set / shift / slice / etc...
@JsOverlay
Collection<T> asCollection() {
// Java API on top of JS API
return new JsArrayCollectionAdapter<>(this);
}
@JsOverlay
List<T> asList() {
// Java API on top of JS API
return new JsArrayListAdapter<>(this);
}
}
@JsType(native = true)
class Something {
@JsProperty
JsArray<Person> persons;
@JsOverlay
List<Person> getPersons() {
return persons.asList();
}
@JsOverlay
void setPersons(List<Person> newPersons) {
// might use ES6 Array.from(newPersons.toArray()) if possible,
otherwise fallback to manual copying
persons = JsUtils.asJsArray(newPersons);
// alternatively do it through the adapter
List<Person> adapter = persons.asList();
adapter.clear();
adapter.addAll(newPersons);
}
}
-- J.
--
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.