Search in sources :

Example 71 with JsonElement

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

the class JsonRpcRequestTest method shouldToStringWhenPassStringParamsWithIdAndWithParams.

@Test
public void shouldToStringWhenPassStringParamsWithIdAndWithParams() {
    when(params.emptyOrAbsent()).thenReturn(false);
    JsonObject expected = request;
    JsonRpcRequest jsonRpcRequest = new JsonRpcRequest("0", "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)

Example 72 with JsonElement

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

the class JsonRpcResultTest method shouldToJsonValueWhenParsingStringWithResultAsASingleNumber.

@Test
public void shouldToJsonValueWhenParsingStringWithResultAsASingleNumber() throws Exception {
    JsonPrimitive expected = new JsonPrimitive(0D);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(expected.toString(), 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 73 with JsonElement

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

the class JsonRpcParamsTest method shouldToJsonForCreatedSingleDoubleParams.

@Test
public void shouldToJsonForCreatedSingleDoubleParams() throws Exception {
    Double expected = 0D;
    JsonRpcParams jsonRpcParams = new JsonRpcParams(expected, jsonParser);
    JsonElement actual = jsonRpcParams.toJsonElement();
    assertEquals(expected, Double.valueOf(actual.toString()));
}
Also used : JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Example 74 with JsonElement

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

the class JsonRpcParamsTest method shouldToJsonValueForParsedListDtoParams.

@Test
public void shouldToJsonValueForParsedListDtoParams() throws Exception {
    JsonArray array = new JsonArray();
    JsonObject jsonObject = jsonParser.parse(DTO_JSON).getAsJsonObject();
    array.add(jsonObject);
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[" + DTO_JSON + "]", jsonParser);
    JsonElement jsonValue = jsonRpcParams.toJsonElement();
    assertEquals(array, jsonValue);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 75 with JsonElement

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

the class JsonRpcErrorTest method shouldToStringProperly.

@Test
public void shouldToStringProperly() {
    JsonRpcError real = new JsonRpcError(ERROR_JSON, jsonParser);
    JsonElement expected = jsonParser.parse(ERROR_JSON);
    assertEquals(real.toJsonObject(), expected);
}
Also used : JsonElement(com.google.gson.JsonElement) 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