I want to read topojson
objects into a Java class. Topojson is a special class of JSON, defined where the objects have arcs in a lookup table as follows:
{
"type":"Topology",
"objects":{
"collection":{
"type":"GeometryCollection",
"geometries":[
{"type":"LineString","properties":{"id":842296681,"start":892624561,"end":892624564,"class":5,"lanes":null,"direction":"B","length":0.000485},"arcs":[0]},
{"type":"LineString","properties":{"id":842296682,"start":892624563,"end":892624564,"class":5,"lanes":null,"direction":"B","length":0.000351},"arcs":[1]},
]
}
},
"arcs":[
[[4816,1007],[262,2281],[183,738]],
[[4397,3892],[341,-268],[235,0],[288,402]]
],
"transform":{
"scale":[3.8203658765624953e-7,1.4901510251040002e-7],
"translate":[-87.63437999816,41.86725999012999]},
"bbox":[-87.63437999816,41.86725999012999,-87.63056001432003,41.86874999213999]
}
I am trying to do as suggested in this answer and read the objects directly into a class, which I've sort of awkwardly defined as
import java.util.ArrayList;
import java.util.Map;
/**
* Created by gregmacfarlane on 7/11/17.
*/
public class TopoJsonNetwork {
String type;
Map<String, GeometryCollection> objects;
ArrayList<Double[][]> arcs;
Transform transform;
}
class GeometryCollection{
String type;
Geometry[] geometries;
}
class Geometry{
String type;
Map<String, String> properties;
Integer[] arcs; // lines will have only a single arc
}
class Transform{
Double[] scale;
Double[] translate;
Double[] bbox;
}
Everything works great when I call the gson reader
reader = new JsonReader(new FileReader(topoFile));
Gson gson = new Gson();
TopoJsonNetwork topoNet = gson.fromJson(reader, TopoJsonNetwork.class);
meaning that all the objects of my class are populated --- except for the arcs
array. The element is there, but with a null
value. What should I change about how this element is defined so that it populates correctly?