Commit cf713a59 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg

Should fix issue #13

parent 03287017
Pipeline #51649 passed with stage
in 2 minutes and 8 seconds
......@@ -56,8 +56,8 @@ public class LatLongSerializer extends JsonSerializer<LatLong> {
}
jsonGen.writeEndArray();
}
jsonGen.writeEndObject();
}
jsonGen.writeEndObject();
}
}
package simpleex.json;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Arrays;
import java.util.Iterator;
......@@ -59,6 +60,34 @@ public class LatLongsJsonTest {
assertEqualsIgnoreWhitespace(expectedJson, actualJson);
}
@Test
public void testLatLongsMetaDataSerialization() {
final LatLong latLong = latLong1();
final MetaData metaData = latLong.getMetaData();
metaData.addTags("aTag", "bTag");
metaData.setProperty("aProperty", "aValue");
final LatLongs latLongs = new LatLongs(latLong);
try {
final String actualJson = objectMapper.writeValueAsString(latLongs);
final String expectedJson = "[{\"latitude\":63.1,\"longitude\":12.3,"
+ "\"metaData\":{\"tags\":[\"aTag\",\"bTag\"],\"properties\":[{\"name\":\"aProperty\",\"value\":\"aValue\"}]}}]";
assertEqualsIgnoreWhitespace(expectedJson, actualJson);
} catch (final JsonProcessingException e) {
Assert.fail();
} catch (final Exception e) {
Assert.fail();
}
}
@Test
public void testLatLongsMetaDataDeserialization() throws Exception {
final String json = "[{\"latitude\":63.1,\"longitude\":12.3,"
+ "\"metaData\":{\"tags\":[\"aTag\",\"bTag\"],\"properties\":[{\"name\":\"aProperty\",\"value\":\"aValue\"}]}}]";
final LatLongs latLongs = objectMapper.readValue(json, LatLongs.class);
Assert.assertEquals(1, latLongs.getLatLongCount());
Assert.assertTrue(latLongs.getLatLong(0).hasMetaData());
}
// relies on a certain order
private void check(final Iterator<String> it, final String... ss) {
final Iterator<String> it1 = Arrays.asList(ss).iterator();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment