Guest User

Untitled

a guest
Jan 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. "geometry":{
  2. "type":"Polygon",
  3. "coordinates":[
  4. [
  5. [
  6. -69.899139,
  7. 12.452005
  8. ],
  9. [
  10. -69.895676,
  11. 12.423015
  12. ],
  13.  
  14. public static final class Coordinate {
  15. public final double[] coord;
  16.  
  17. public Coordinate(double[] coord) {
  18. this.coord = coord;
  19. }
  20. }
  21.  
  22. import org.apache.commons.lang3.ArrayUtils;
  23. import com.google.gson.Gson;
  24.  
  25. public class Scratch {
  26. public static void main(String[] args) throws Exception {
  27. String json = "{" +
  28. " "geometry": {" +
  29. " "type": "Polygon"," +
  30. " "coordinates": [" +
  31. " [" +
  32. " [-69.899139," +
  33. " 12.452005" +
  34. " ]," +
  35. " [-69.895676," +
  36. " 12.423015" +
  37. " ]" +
  38. " ]" +
  39. " ]" +
  40. " }" +
  41. "}";
  42.  
  43. Geometry g = new Gson().fromJson(json, Geometry.class);
  44. System.out.println(g);
  45. // Geometry [geometry=GeometryData [type=Polygon, coordinates={{{-69.899139,12.452005},{-69.895676,12.423015}}}]]
  46. }
  47. }
  48. class Geometry {
  49. GeometryData geometry;
  50.  
  51. @Override
  52. public String toString() {
  53. return "Geometry [geometry=" + geometry + "]";
  54. }
  55. }
  56. class GeometryData {
  57. String type;
  58. double[][][] coordinates;
  59.  
  60. @Override
  61. public String toString() {
  62. return "GeometryData [type=" + type + ", coordinates=" + ArrayUtils.toString(coordinates) + "]";
  63. }
  64. }
Add Comment
Please, Sign In to add comment