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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations