Search in sources :

Example 11 with JSONArray

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))));
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONArray(com.github.openjson.JSONArray) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 12 with JSONArray

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)));
}
Also used : JSONArray(com.github.openjson.JSONArray) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 13 with JSONArray

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()));
}
Also used : JSONArray(com.github.openjson.JSONArray) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 14 with JSONArray

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))));
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONArray(com.github.openjson.JSONArray) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 15 with JSONArray

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()));
}
Also used : JSONArray(com.github.openjson.JSONArray) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Aggregations

JSONArray (com.github.openjson.JSONArray)35 JSONObject (com.github.openjson.JSONObject)30 Test (org.junit.jupiter.api.Test)11 List (java.util.List)5 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)5 ArrayList (java.util.ArrayList)4 Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)4 Form (javax.ws.rs.core.Form)3 Response (javax.ws.rs.core.Response)3 JSONException (com.github.openjson.JSONException)2 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Client (org.apache.openmeetings.db.entity.basic.Client)2 Room (org.apache.openmeetings.db.entity.room.Room)2 RoomElement (org.apache.openmeetings.db.entity.room.Room.RoomElement)2 NullStringer (org.apache.openmeetings.util.NullStringer)2 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)2