1 package org.geojson.jackson; 2 3 import com.fasterxml.jackson.databind.ObjectMapper; 4 import org.geojson.*; 5 import org.junit.Test; 6 7 import static org.junit.Assert.*; 8 9 public class GeometryCollectionTest { 10 11 private ObjectMapper mapper = new ObjectMapper(); 12 13 @Test itShouldSerialize()14 public void itShouldSerialize() throws Exception { 15 GeometryCollection gc = new GeometryCollection(); 16 gc.add(new Point(100, 0)); 17 gc.add(new LineString(new LngLatAlt(101, 0), new LngLatAlt(102, 1))); 18 assertEquals("{\"type\":\"GeometryCollection\"," 19 + "\"geometries\":[{\"type\":\"Point\",\"coordinates\":[100.0,0.0]}," 20 + "{\"type\":\"LineString\",\"coordinates\":[[101.0,0.0],[102.0,1.0]]}]}", 21 mapper.writeValueAsString(gc)); 22 } 23 24 @Test itShouldDeserialize()25 public void itShouldDeserialize() throws Exception { 26 GeometryCollection geometryCollection = mapper 27 .readValue("{\"type\":\"GeometryCollection\"," 28 + "\"geometries\":[{\"type\":\"Point\",\"coordinates\":[100.0,0.0]}," 29 + "{\"type\":\"LineString\",\"coordinates\":[[101.0,0.0],[102.0,1.0]]}]}", 30 GeometryCollection.class); 31 assertNotNull(geometryCollection); 32 } 33 34 @Test itShouldDeserializeSubtype()35 public void itShouldDeserializeSubtype() throws Exception { 36 FeatureCollection collection = mapper 37 .readValue("{\"type\": \"FeatureCollection\"," 38 + " \"features\": [" 39 + " {" 40 + " \"type\": \"Feature\"," 41 + " \"geometry\": {" 42 + " \"type\": \"GeometryCollection\"," 43 + " \"geometries\": [" 44 + " {" 45 + " \"type\": \"Point\"," 46 + " \"coordinates\": [100.0, 0.0]" 47 + " }" 48 + " ]" 49 + " }" 50 + " }" 51 + " ]" 52 + "}", 53 FeatureCollection.class); 54 assertNotNull(collection); 55 assertTrue(collection.getFeatures().get(0).getGeometry() instanceof GeometryCollection); 56 } 57 } 58