Search in sources :

Example 81 with JsonArray

use of com.google.gson.JsonArray 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)

Example 82 with JsonArray

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

the class JsonRpcParamsTest method shouldToStringForParsedListDtoParams.

@Test
public void shouldToStringForParsedListDtoParams() throws Exception {
    JsonArray array = new JsonArray();
    JsonObject jsonObject = jsonParser.parse(DTO_JSON).getAsJsonObject();
    array.add(jsonObject);
    String expected = array.toString();
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[" + DTO_JSON + "]", jsonParser);
    String actual = jsonRpcParams.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 83 with JsonArray

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

the class JsonRpcParamsTest method shouldToStringCreatedListStringParams.

@Test
public void shouldToStringCreatedListStringParams() throws Exception {
    String value = "value";
    JsonArray array = new JsonArray();
    array.add(new JsonPrimitive(value));
    String expected = array.toString();
    JsonRpcParams jsonRpcParams = new JsonRpcParams(singletonList(value), jsonParser);
    String actual = jsonRpcParams.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 84 with JsonArray

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

the class JsonRpcParamsTest method shouldToJsonValueForParsedListDoubleParams.

@Test
public void shouldToJsonValueForParsedListDoubleParams() throws Exception {
    Double expected = 0D;
    JsonArray array = new JsonArray();
    array.add(new JsonPrimitive(expected));
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[" + expected + "]", jsonParser);
    JsonElement jsonValue = jsonRpcParams.toJsonElement();
    assertEquals(array, jsonValue);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Example 85 with JsonArray

use of com.google.gson.JsonArray in project groupme-utils by TheGuyWithTheFace.

the class GroupDeserializer method deserialize.

@Override
public Group deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject json = getResponse(jsonElement).getAsJsonObject();
    GroupBuilder g = new GroupBuilder();
    g.setId(json.get("id").getAsString());
    g.setName(json.get("name").getAsString());
    g.setType(json.get("type").getAsString());
    g.setDescription(json.get("description").getAsString());
    if (!json.get("image_url").isJsonNull()) {
        g.setImageUrl(json.get("image_url").getAsString());
    }
    g.setCreatorUserId(json.get("creator_user_id").getAsString());
    long createTime = json.get("created_at").getAsLong();
    g.setCreatedAt(Instant.ofEpochSecond(createTime));
    long updateTime = json.get("updated_at").getAsLong();
    g.setUpdatedAt(Instant.ofEpochSecond(updateTime));
    if (!json.get("share_url").isJsonNull()) {
        g.setShareUrl(json.get("share_url").getAsString());
    }
    // Get members of the group
    JsonArray response = json.get("members").getAsJsonArray();
    int numMembers = response.size();
    Member[] members = new Member[numMembers];
    for (int i = 0; i < numMembers; i++) {
        JsonElement elem = response.get(i);
        members[i] = context.deserialize(elem, Member.class);
    }
    g.setMembers(members);
    // TODO this will be reworked later, see note in Group Class.
    JsonObject messages = json.get("messages").getAsJsonObject();
    g.setMessageCount(messages.get("count").getAsInt());
    g.setLastMessageId(messages.get("last_message_id").getAsString());
    long lastCreate = messages.get("last_message_created_at").getAsLong();
    g.setLastMessageCreatedAt(Instant.ofEpochSecond(lastCreate));
    return g.createGroup();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) GroupBuilder(me.perrycate.groupmeutils.data.GroupBuilder) JsonObject(com.google.gson.JsonObject) Member(me.perrycate.groupmeutils.data.Member)

Aggregations

JsonArray (com.google.gson.JsonArray)424 JsonObject (com.google.gson.JsonObject)290 JsonElement (com.google.gson.JsonElement)167 JsonPrimitive (com.google.gson.JsonPrimitive)118 Test (org.testng.annotations.Test)59 JsonParser (com.google.gson.JsonParser)57 ArrayList (java.util.ArrayList)50 HashMap (java.util.HashMap)34 Map (java.util.Map)34 Gson (com.google.gson.Gson)22 IOException (java.io.IOException)17 Test (org.junit.Test)16 Type (java.lang.reflect.Type)12 List (java.util.List)11 Matchers.anyString (org.mockito.Matchers.anyString)10 TextView (android.widget.TextView)9 Point (android.graphics.Point)8 JsonParseException (com.google.gson.JsonParseException)7 GsonUtilities.jboolean (com.ibm.streamsx.topology.internal.gson.GsonUtilities.jboolean)7 KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)6