Search code examples
jsongwtautobean

AutoBean complex JSON parse


I have a complex JSON String and i try to parse it using AutoBean.

The JSON String looks like :

 `{
 "status": "OK",
 "result": {
  "geometry": [
   [
    {
     "X": 268347.4,
     "Y": 6743983.1
    },
    {
     "X": 268341.1,
     "Y": 6743989.7
    }
   ],
   [
    {
     "X": 268378.15,
     "Y": 6743972.7
    },
    {
     "X": 268347.4,
     "Y": 6743983.1
    }
   ]
  ]
 }
}`

I have created this interface

public interface BrancheAutoBean {

  String getResult();
  GeometryModel getGeometryModel()
}

public interface GeometryModel {
  @PropertyName("geometry")
    List<Geometry> getGeometry();
}

public interface Geometry{

  @PropertyName("X")
   Double getX();

  @PropertyName("Y")
   Double getY();
}

How can I make it work? And how to add the X and Y array to the geomtry i found some example like adding the X and Y when parsing the bean:

Geometry bean =AutoBeanCodex.decode(factory, GeometryModel.class, "{\"Geometry\": " + strResponse + "}").as();

but my application must implement générique parsing. thanx in advence.


Solution

  • Your BrancheAutoBean are either misnamed or lacking @PropertyName annotations: result should be status, and geometryModel should be result.

    Then, your GeometryModel's getGeometry should be a List<List<Geometry>>. I'm not sure this is supported by AutoBean though.