List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:de.winniehell.battlebeavers.storage.WayPointDeserializer.java
License:Open Source License
@Override public WayPoint deserialize(final JsonElement pJson, final Type pType, final JsonDeserializationContext pContext) throws JsonParseException { if (!pJson.isJsonObject()) { return null; }/*from w w w . j a v a 2 s .co m*/ final JsonObject object = pJson.getAsJsonObject(); if (!object.has("tile") || (SoldierDeserializer.currentSoldier == null)) { return null; } WeightedPath path = null; if (object.has("path")) { path = (WeightedPath) pContext.deserialize(object.get("path"), WeightedPath.class); } final WayPoint waypoint = new WayPoint(SoldierDeserializer.currentSoldier, path, (Tile) pContext.deserialize(object.get("tile"), Tile.class)); if (object.has("aim") && !object.get("aim").isJsonNull()) { waypoint.setAim((Tile) pContext.deserialize(object.get("aim"), Tile.class)); } if (object.has("wait") && !object.get("wait").isJsonNull()) { waypoint.setWait(object.get("wait").getAsInt()); } return waypoint; }
From source file:de.winniehell.battlebeavers.storage.WeightedPathDeserializer.java
License:Open Source License
@Override public WeightedPath deserialize(final JsonElement pJson, final Type pType, final JsonDeserializationContext pContext) throws JsonParseException { if (!pJson.isJsonArray()) { return null; }/* w ww . ja v a 2 s. com*/ // TODO read path cost final WeightedPath path = new WeightedPath(0); for (final JsonElement step : pJson.getAsJsonArray()) { path.append((Step) pContext.deserialize(step, Step.class)); } return path; }
From source file:dev.maisentito.liburban.DefinitionDeserializer.java
License:Open Source License
@Override public Definition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { RawDefinition raw = context.deserialize(json, RawDefinition.class); Definition def = new Definition(); def.setId(raw.defid);/*from w ww . j a v a 2 s .com*/ def.setWord(raw.word); def.setAuthor(raw.author); def.setLink(raw.permalink); def.setDefinition(raw.definition.replace("\r", "")); def.setExample(raw.example.replace("\r", "")); def.setThumbsUp(raw.thumbs_up); def.setThumbsDown(raw.thumbs_down); def.setCurrentVote(raw.current_vote); return def; }
From source file:dev.maisentito.liburban.ResultsDeserializer.java
License:Open Source License
@Override public Results deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { RawResults raw = context.deserialize(json, RawResults.class); Results res = new Results(); res.setTags(Arrays.asList(raw.tags)); // TODO Type/*from www .ja va 2s . com*/ if (raw.result_type.equals("exact")) { res.setType(Results.Type.EXACT); } else if (raw.result_type.equals("no_results")) { res.setType(Results.Type.NO_RESULTS); } res.setList(Arrays.asList(raw.list)); res.setSounds(Arrays.asList(raw.sounds)); return res; }
From source file:diffboat.type.json.ArticleJsonDeserializer.java
License:Open Source License
@Override public Article deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = (JsonObject) json; Article article = new Article(asString(jsonObject.get("title")), asString(jsonObject.get("text")), asString(jsonObject.get("date")), asString(jsonObject.get("author")), (Medias) context.deserialize(jsonObject.get("media"), Medias.class), asString(jsonObject.get("xpath")), asString(jsonObject.get("icon")), asString(jsonObject.get("url")), asString(jsonObject.get("resolved_url"))); article.setHtml(asString(jsonObject.get("html"))); article.setTags((String[]) context.deserialize(jsonObject.get("tags"), String[].class)); article.setSummary(asString(jsonObject.get("summary"))); return article; }
From source file:diffboat.type.json.MediasJsonDeserializer.java
License:Open Source License
@Override public Medias deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Medias medias = new Medias(); if (json instanceof JsonArray) { for (JsonElement element : (JsonArray) json) { medias.add((Media) context.deserialize(element, Media.class)); }//from www.ja v a 2 s . c om } return medias; }
From source file:edu.isi.wings.portal.classes.JsonHandler.java
License:Apache License
public Binding deserialize(JsonElement el, Type typeOfSrc, JsonDeserializationContext context) { if (el.isJsonArray()) { Binding b = new Binding(); for (JsonElement cel : el.getAsJsonArray()) { b.add((Binding) context.deserialize(cel, Binding.class)); }// w w w .ja v a 2s . c om return b; } else { JsonObject obj = (JsonObject) el; if (obj.get("type") == null) return null; String type = obj.get("type").getAsString(); if ("uri".equals(type)) return new Binding(obj.get("id").getAsString()); else if ("literal".equals(type)) { String datatype = obj.get("datatype") != null ? obj.get("datatype").getAsString() : KBUtils.XSD + "string"; return new ValueBinding(obj.get("value").getAsString(), datatype); } } return null; }
From source file:edu.isi.wings.portal.classes.JsonHandler.java
License:Apache License
public SetExpression deserialize(JsonElement el, Type typeOfSrc, JsonDeserializationContext context) { if (el.isJsonObject()) { JsonObject obj = el.getAsJsonObject(); SetOperator op = context.deserialize(obj.get("op"), SetOperator.class); SetExpression expr = new SetExpression(op); for (JsonElement arg : obj.getAsJsonArray("args")) { expr.add((SetExpression) context.deserialize(arg, SetExpression.class)); }// w w w . ja v a 2 s. c o m return expr; } else { String portid = el.getAsString(); Port port = new Port(portid); return new SetExpression(SetOperator.XPRODUCT, port); } }
From source file:edu.temple.tutrucks.MenuDeserializer.java
@Override public Menu deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); final int id = jsonObject.get("id").getAsInt(); final String menuName = jsonObject.get("menuName").getAsString(); final String menuDescription = jsonObject.get("description").getAsString(); Item[] itemArray = context.deserialize(jsonObject.get("items"), Item[].class); Set<Item> itemSet = new HashSet<>(Arrays.asList(itemArray)); final Menu menu; if (id != 0) { menu = Menu.getMenubyId(id); } else {//from ww w . j ava 2 s . c o m menu = new Menu(); menu.setId(0); } menu.setDescription(menuDescription); menu.setMenuName(menuName); menu.setItems(itemSet); return menu; }
From source file:edu.wpi.cs.wpisuitetng.modules.defecttracker.models.DefectChangesetDeserializer.java
License:Open Source License
@Override public DefectChangeset deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { // hash map to hold the deserialized FieldChange objects HashMap<String, FieldChange<?>> changesMap = new HashMap<String, FieldChange<?>>(); JsonObject changeSet = json.getAsJsonObject(); if (changeSet.has("changes")) { JsonObject changes = changeSet.get("changes").getAsJsonObject(); if (changes.has("title")) { JsonObject titleObj = changes.get("title").getAsJsonObject(); String oldTitle = context.deserialize(titleObj.get("oldValue"), String.class); String newTitle = context.deserialize(titleObj.get("newValue"), String.class); changesMap.put("title", new FieldChange<String>(oldTitle, newTitle)); }//from www .ja v a2 s . c o m if (changes.has("description")) { JsonObject descriptionObj = changes.get("description").getAsJsonObject(); String oldDesc = context.deserialize(descriptionObj.get("oldValue"), String.class); String newDesc = context.deserialize(descriptionObj.get("newValue"), String.class); changesMap.put("description", new FieldChange<String>(oldDesc, newDesc)); } if (changes.has("assignee")) { JsonObject assigneeObj = changes.get("assignee").getAsJsonObject(); User oldUser = context.deserialize(assigneeObj.get("oldValue"), User.class); User newUser = context.deserialize(assigneeObj.get("newValue"), User.class); changesMap.put("assignee", new FieldChange<User>(oldUser, newUser)); } if (changes.has("tags")) { JsonObject tagsObj = changes.get("tags").getAsJsonObject(); Tag[] oldTags = context.deserialize(tagsObj.get("oldValue"), Tag[].class); Tag[] newTags = context.deserialize(tagsObj.get("newValue"), Tag[].class); changesMap.put("tags", new FieldChange<Set<Tag>>(new HashSet<Tag>(new ArrayList<Tag>(Arrays.asList(oldTags))), new HashSet<Tag>(new ArrayList<Tag>(Arrays.asList(newTags))))); } if (changes.has("status")) { JsonObject statusObj = changes.get("status").getAsJsonObject(); DefectStatus oldStatus = context.deserialize(statusObj.get("oldValue"), DefectStatus.class); DefectStatus newStatus = context.deserialize(statusObj.get("newValue"), DefectStatus.class); changesMap.put("status", new FieldChange<DefectStatus>(oldStatus, newStatus)); } // reconstruct the DefectChangeset DefectChangeset retVal = new DefectChangeset(); retVal.setChanges(changesMap); retVal.setDate((Date) (context.deserialize(changeSet.get("date"), Date.class))); retVal.setUser((User) (context.deserialize(changeSet.get("user"), User.class))); // return the DefectChangeset return retVal; } else { throw new JsonParseException("DefectChangeset type is unrecognized"); } }