0

I have my expansive server side java objects that implement these simplified interfaces:

interface Vector {
  public double getX();
  public double getY();
}

interface Geometry {
  public List<Vector> getShell();//can get big
  public List<List<Vector>> getHoles();
}

interface Feature {
  public String getID();
  public List<Geometry> getGeometry();
}

I construct a list of features that I convert to json using gson lib. The result looks like this, except that it's a lot bigger.

[{"i":"304","g":[{"s":[{"x":-3169996.4370428286,"y":1.1231962684336938E7},{"x":-3287403.71248886,"y":1.1192826925854929E7},{"x":-2935181.88615077,"y":1.115369116737292E7}....

I am able to parse the json into a JsArray where JsFeature is a javascriptobject that implements the feature interface.

How do I get the rest of the data without having to parse through my json vector by vector. Ideally, I would like to have a way to convert the List into JsList where JsGeometry is a JavascriptObject class implementing Geometry, which would include a List and so on and so forth..

1 Answer 1

1

You could implement a List class that delegates everything to an underlying JsArray, but that's not as easy as it sounds (and why it's not built-in GWT).

I'd rather recommend using AutoBean:

interface Factory extends AutoBeanFactory {
   AutoBean<Feature> feature();
}

Factory factory = GWT.create(Factory.class);

Feature feature = AutoBeanCodex.decode(factory, Feature.class, jsonString).as();

The runtime overhead is minimal, almost the same as a List wrapping a JsArray but you don't have to code anything to make it work.

Also note you could even use AutoBean on the server-side instead of GSON.

Sign up to request clarification or add additional context in comments.

2 Comments

would I be able to get the underlying List<Geometry> just by AutoBeaning the feature class??
Absolutely! You don't have to change anything to your interfaces, just use the AutoBeanFactory and AutoBeanCodex and you're done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.