Search in sources :

Example 76 with JsonElement

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

the class JsonRpcErrorTest method shouldToJsonObjectProperly.

@Test
public void shouldToJsonObjectProperly() {
    JsonRpcError real = new JsonRpcError(ERROR_JSON, jsonParser);
    JsonElement expected = jsonParser.parse(ERROR_JSON);
    assertTrue(real.toJsonObject().equals(expected));
}
Also used : JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Example 77 with JsonElement

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

the class JsonRpcResultTest method shouldToJsonValueWhenPassingParametersWithResultAsAListOfDto.

@Test
public void shouldToJsonValueWhenPassingParametersWithResultAsAListOfDto() throws Exception {
    JsonArray expected = new JsonArray();
    JsonObject value = jsonParser.parse(dto.toString()).getAsJsonObject();
    expected.add(value);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(singletonList(dto), jsonParser);
    JsonElement actual = jsonRpcResult.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 78 with JsonElement

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

the class JsonRpcResultTest method shouldToJsonValueWhenParsingStringWithResultAsASingleString.

@Test
public void shouldToJsonValueWhenParsingStringWithResultAsASingleString() throws Exception {
    JsonPrimitive expected = new JsonPrimitive("a");
    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 79 with JsonElement

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

the class JsonRpcResultTest method shouldToJsonValueWhenPassingParametersWithResultAsAListOfNumber.

@Test
public void shouldToJsonValueWhenPassingParametersWithResultAsAListOfNumber() throws Exception {
    Double value = 0D;
    JsonPrimitive primitive = new JsonPrimitive(value);
    JsonArray expected = new JsonArray();
    expected.add(primitive);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(singletonList(value), jsonParser);
    JsonElement actual = jsonRpcResult.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 80 with JsonElement

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

the class JsonRpcParamsTest method shouldToJsonForCreatedListDtoParams.

@Test
public void shouldToJsonForCreatedListDtoParams() throws Exception {
    List<Dto> list = singletonList(dto);
    JsonArray expected = new JsonArray();
    JsonElement element = jsonParser.parse(dto.toString());
    expected.add(element);
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonParser);
    JsonElement actual = jsonRpcParams.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) 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