Search in sources :

Example 31 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 32 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)

Example 33 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 34 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 35 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)

Aggregations

JsonElement (com.google.gson.JsonElement)398 JsonObject (com.google.gson.JsonObject)221 JsonArray (com.google.gson.JsonArray)121 JsonParser (com.google.gson.JsonParser)88 Map (java.util.Map)55 HashMap (java.util.HashMap)49 JsonPrimitive (com.google.gson.JsonPrimitive)48 Gson (com.google.gson.Gson)47 ArrayList (java.util.ArrayList)45 Test (org.testng.annotations.Test)45 IOException (java.io.IOException)40 JsonReader (com.google.gson.stream.JsonReader)30 StringReader (java.io.StringReader)21 Test (org.junit.Test)19 GsonBuilder (com.google.gson.GsonBuilder)18 InputStreamReader (java.io.InputStreamReader)18 Type (java.lang.reflect.Type)17 JsonParseException (com.google.gson.JsonParseException)15 AssetManager (android.content.res.AssetManager)10 List (java.util.List)10