Search in sources :

Example 26 with JSONObject

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

the class TripleAForumPoster method login.

private JSONObject login(final CloseableHttpClient client) throws IOException {
    final HttpPost post = new HttpPost(tripleAForumURL + "/api/ns/login");
    post.setEntity(new UrlEncodedFormEntity(Arrays.asList(newUsernameParameter(), newPasswordParameter()), StandardCharsets.UTF_8));
    HttpProxy.addProxy(post);
    try (CloseableHttpResponse response = client.execute(post)) {
        final String rawJson = EntityUtils.toString(response.getEntity());
        return new JSONObject(rawJson);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) JSONObject(com.github.openjson.JSONObject) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 27 with JSONObject

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

the class TripleAForumPoster method getUserId.

private int getUserId(final CloseableHttpClient client) throws IOException {
    final JSONObject jsonObject = login(client);
    checkUser(jsonObject);
    return jsonObject.getInt("uid");
}
Also used : JSONObject(com.github.openjson.JSONObject)

Example 28 with JSONObject

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

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

the class OpenJsonUtilsTest method toMap_ShouldReturnMapContainingJsonObjectProperties.

@Test
public void toMap_ShouldReturnMapContainingJsonObjectProperties() {
    final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name1", "value1", "name2", 2, "name3", 3.0));
    final Map<String, Object> properties = OpenJsonUtils.toMap(jsonObject);
    assertThat(properties, is(ImmutableMap.of("name1", "value1", "name2", 2, "name3", 3.0)));
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 30 with JSONObject

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

the class OpenJsonUtilsTest method toMap_ShouldConvertJsonObjectValueToMap.

@Test
public void toMap_ShouldConvertJsonObjectValueToMap() {
    final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name", new JSONObject(ImmutableMap.of("childName", 42))));
    final Map<String, Object> properties = OpenJsonUtils.toMap(jsonObject);
    assertThat(properties, is(ImmutableMap.of("name", ImmutableMap.of("childName", 42))));
}
Also used : JSONObject(com.github.openjson.JSONObject) 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