Search in sources :

Example 26 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 27 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)

Example 28 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 29 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 30 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)

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