Search in sources :

Example 31 with JSONObject

use of com.github.openjson.JSONObject 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 32 with JSONObject

use of com.github.openjson.JSONObject in project triplea by triplea-game.

the class OpenJsonUtilsTest method optEnum_ShouldThrowExceptionWhenPresentButNotEnumValue.

@Test
public void optEnum_ShouldThrowExceptionWhenPresentButNotEnumValue() {
    final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name", "unknown"));
    assertThrows(IllegalArgumentException.class, () -> OpenJsonUtils.optEnum(jsonObject, TestEnum.class, "name", TestEnum.SECOND));
}
Also used : JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 33 with JSONObject

use of com.github.openjson.JSONObject 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)

Example 34 with JSONObject

use of com.github.openjson.JSONObject in project triplea by triplea-game.

the class OpenJsonUtilsTest method optEnum_ShouldReturnDefaultValueWhenAbsent.

@Test
public void optEnum_ShouldReturnDefaultValueWhenAbsent() {
    final JSONObject jsonObject = new JSONObject();
    final TestEnum value = OpenJsonUtils.optEnum(jsonObject, TestEnum.class, "name", TestEnum.SECOND);
    assertThat(value, is(TestEnum.SECOND));
}
Also used : JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 35 with JSONObject

use of com.github.openjson.JSONObject in project triplea by triplea-game.

the class OpenJsonUtilsTest method optEnum_ShouldReturnEnumValueWhenPresent.

@Test
public void optEnum_ShouldReturnEnumValueWhenPresent() {
    final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name", TestEnum.FIRST.toString()));
    final TestEnum value = OpenJsonUtils.optEnum(jsonObject, TestEnum.class, "name", TestEnum.SECOND);
    assertThat(value, is(TestEnum.FIRST));
}
Also used : JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Aggregations

JSONObject (com.github.openjson.JSONObject)64 JSONArray (com.github.openjson.JSONArray)23 Test (org.junit.jupiter.api.Test)11 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)7 Client (org.apache.openmeetings.db.entity.basic.Client)7 ArrayList (java.util.ArrayList)6 Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)6 NullStringer (org.apache.openmeetings.util.NullStringer)6 Form (javax.ws.rs.core.Form)5 Response (javax.ws.rs.core.Response)5 List (java.util.List)4 Map (java.util.Map)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)3 Room (org.apache.openmeetings.db.entity.room.Room)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 JSONFunction (org.apache.wicket.ajax.json.JSONFunction)3 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)3 JSONException (com.github.openjson.JSONException)2