Search in sources :

Example 66 with JsonElement

use of com.google.gson.JsonElement in project che by eclipse.

the class JsonRpcResponseTest method shouldToStringWhenParsingStringWithError.

@Test
public void shouldToStringWhenParsingStringWithError() throws Exception {
    JsonObject expected = response;
    expected.remove("result");
    JsonRpcResponse jsonRpcResponse = new JsonRpcResponse(expected.toString(), jsonParser);
    JsonElement actual = jsonParser.parse(jsonRpcResponse.toString());
    assertEquals(expected, actual);
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 67 with JsonElement

use of com.google.gson.JsonElement in project che by eclipse.

the class JsonRpcResultTest method shouldToJsonValueWhenPassingParametersWithResultAsASingleString.

@Test
public void shouldToJsonValueWhenPassingParametersWithResultAsASingleString() throws Exception {
    String value = "a";
    JsonPrimitive expected = new JsonPrimitive(value);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(value, jsonParser);
    JsonElement actual = jsonRpcResult.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Example 68 with JsonElement

use of com.google.gson.JsonElement in project che by eclipse.

the class JsonRpcParamsTest method shouldToJsonForCreatedListDoubleParams.

@Test
public void shouldToJsonForCreatedListDoubleParams() throws Exception {
    double value = 0D;
    List<Double> list = singletonList(value);
    JsonArray expected = new JsonArray();
    expected.add(new JsonPrimitive(value));
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonParser);
    JsonElement actual = jsonRpcParams.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Example 69 with JsonElement

use of com.google.gson.JsonElement in project che by eclipse.

the class JsonRpcParamsTest method shouldToJsonForCreatedSingleDtoParams.

@Test
public void shouldToJsonForCreatedSingleDtoParams() throws Exception {
    JsonObject expected = jsonParser.parse(dto.toString()).getAsJsonObject();
    JsonRpcParams jsonRpcParams = new JsonRpcParams(dto, jsonParser);
    JsonElement actual = jsonRpcParams.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 70 with JsonElement

use of com.google.gson.JsonElement in project che by eclipse.

the class JsonRpcRequestTest method shouldToStringWhenPassStringParamsWithoutIdAndWithoutParams.

@Test
public void shouldToStringWhenPassStringParamsWithoutIdAndWithoutParams() {
    when(params.emptyOrAbsent()).thenReturn(true);
    JsonObject expected = request;
    expected.remove("params");
    expected.remove("id");
    JsonRpcRequest jsonRpcRequest = new JsonRpcRequest("method", params, jsonParser);
    JsonElement actual = jsonParser.parse(jsonRpcRequest.toString());
    assertEquals(expected, actual);
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Aggregations

JsonElement (com.google.gson.JsonElement)682 JsonObject (com.google.gson.JsonObject)381 JsonArray (com.google.gson.JsonArray)166 JsonPrimitive (com.google.gson.JsonPrimitive)107 JsonParser (com.google.gson.JsonParser)105 Gson (com.google.gson.Gson)69 Map (java.util.Map)63 ArrayList (java.util.ArrayList)51 HashMap (java.util.HashMap)50 IOException (java.io.IOException)48 Test (org.testng.annotations.Test)45 JsonReader (com.google.gson.stream.JsonReader)31 InputStreamReader (java.io.InputStreamReader)28 GsonBuilder (com.google.gson.GsonBuilder)26 Pager (com.willshex.blogwt.shared.api.Pager)26 Type (java.lang.reflect.Type)25 StringReader (java.io.StringReader)21 Test (org.junit.Test)21 User (com.willshex.blogwt.shared.api.datatype.User)19 JsonParseException (com.google.gson.JsonParseException)17