use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method toList_ShouldConvertJsonObjectValueToMap.
@Test
public void toList_ShouldConvertJsonObjectValueToMap() {
final JSONArray jsonArray = new JSONArray(Arrays.asList(new JSONObject(ImmutableMap.of("name", 42))));
final List<Object> elements = OpenJsonUtils.toList(jsonArray);
assertThat(elements, is(Arrays.asList(ImmutableMap.of("name", 42))));
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method streamJsonArray_ShouldNotConvertNullSentinelValue.
@Test
public void streamJsonArray_ShouldNotConvertNullSentinelValue() {
final JSONArray jsonArray = new JSONArray(Arrays.asList(JSONObject.NULL));
final List<Object> elements = OpenJsonUtils.stream(jsonArray).collect(Collectors.toList());
assertThat(elements, is(Arrays.asList(JSONObject.NULL)));
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method toList_ShouldReturnEmptyListWhenJsonArrayIsEmpty.
@Test
public void toList_ShouldReturnEmptyListWhenJsonArrayIsEmpty() {
final JSONArray jsonArray = new JSONArray();
final List<Object> elements = OpenJsonUtils.toList(jsonArray);
assertThat(elements, is(empty()));
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method toMap_ShouldConvertJsonArrayValueToList.
@Test
public void toMap_ShouldConvertJsonArrayValueToList() {
final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name", new JSONArray(Arrays.asList(42))));
final Map<String, Object> properties = OpenJsonUtils.toMap(jsonObject);
assertThat(properties, is(ImmutableMap.of("name", Arrays.asList(42))));
}
use of com.github.openjson.JSONArray in project triplea by triplea-game.
the class OpenJsonUtilsTest method toList_ShouldConvertNullSentinelValueToNull.
@Test
public void toList_ShouldConvertNullSentinelValueToNull() {
final JSONArray jsonArray = new JSONArray(Arrays.asList(JSONObject.NULL));
final List<Object> elements = OpenJsonUtils.toList(jsonArray);
// NB: need to test using reference equality because JSONObject#NULL#equals() is defined to be equal to null
assertThat(elements.get(0), is(nullValue()));
}
Aggregations