List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:jKlout2.gson.InfluenceItemListDeserializer.java
License:Apache License
public List<InfluenceItem> deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { List<InfluenceItem> output = new ArrayList<InfluenceItem>(); JsonArray items = je.getAsJsonArray(); for (int i = 0; i < items.size(); i++) { JsonElement row = items.get(i);/* w w w .j a v a2 s . c om*/ JsonElement innerItem = row.getAsJsonObject().get("entity"); InfluenceItem iItem = jdc.deserialize(innerItem, InfluenceItem.class); output.add(iItem); } return output; }
From source file:jk_5.nailed.api.chat.serialization.BaseComponentSerializer.java
License:Open Source License
protected void deserialize(@Nonnull JsonObject object, @Nonnull BaseComponent component, @Nonnull JsonDeserializationContext context) { if (object.has("color")) { component.setColor(ChatColor.valueOf(object.get("color").getAsString().toUpperCase())); }/* w ww. ja v a 2 s . c o m*/ if (object.has("bold")) { component.setBold(object.get("bold").getAsBoolean()); } if (object.has("italic")) { component.setItalic(object.get("italic").getAsBoolean()); } if (object.has("underlined")) { component.setUnderlined(object.get("underlined").getAsBoolean()); } if (object.has("strikethrough")) { component.setUnderlined(object.get("strikethrough").getAsBoolean()); } if (object.has("obfuscated")) { component.setUnderlined(object.get("obfuscated").getAsBoolean()); } if (object.has("extra")) { component.setExtra(Arrays .asList(context.<BaseComponent[]>deserialize(object.get("extra"), BaseComponent[].class))); } //Events if (object.has("clickEvent")) { JsonObject event = object.getAsJsonObject("clickEvent"); component.setClickEvent( new ClickEvent(ClickEvent.Action.valueOf(event.get("action").getAsString().toUpperCase()), event.get("value").getAsString())); } if (object.has("hoverEvent")) { JsonObject event = object.getAsJsonObject("hoverEvent"); BaseComponent[] res; if (event.get("value").isJsonArray()) { res = context.deserialize(event.get("value"), BaseComponent[].class); } else { res = new BaseComponent[] { context.<BaseComponent>deserialize(event.get("value"), BaseComponent.class) }; } component.setHoverEvent(new HoverEvent( HoverEvent.Action.valueOf(event.get("action").getAsString().toUpperCase()), res)); } }
From source file:jk_5.nailed.api.chat.serialization.ComponentSerializer.java
License:Open Source License
@Nonnull @Override//ww w .j a v a 2 s .c o m public BaseComponent deserialize(@Nonnull JsonElement json, @Nonnull Type typeOfT, @Nonnull JsonDeserializationContext context) throws JsonParseException { if (json.isJsonPrimitive()) { return new TextComponent(json.getAsString()); } JsonObject object = json.getAsJsonObject(); if (object.has("translate")) { return context.deserialize(json, TranslatableComponent.class); } return context.deserialize(json, TextComponent.class); }
From source file:jk_5.nailed.api.chat.serialization.TranslatableComponentSerializer.java
License:Open Source License
@Override public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { TranslatableComponent component = new TranslatableComponent(); JsonObject object = json.getAsJsonObject(); deserialize(object, component, context); component.setTranslate(object.get("translate").getAsString()); if (object.has("with")) { component.setWith(Arrays// w w w .j a v a 2 s .c om .asList((BaseComponent[]) context.deserialize(object.get("with"), BaseComponent[].class))); } return component; }
From source file:light.mvc.utils.echarts.json.AxisDeserializer.java
License:Open Source License
@Override /**// ww w . j a va 2s . c o m * json,typeOfT,context * * @param json * @param typeOfT * @param context */ public Axis deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); String _type = jsonObject.get("type").getAsString(); AxisType type = AxisType.valueOf(_type); Axis axis = null; switch (type) { case category: axis = context.deserialize(jsonObject, CategoryAxis.class); break; case value: axis = context.deserialize(jsonObject, ValueAxis.class); break; } return axis; }
From source file:managerindustry.logic.apiEsiJson.industry.listSolarSystemCostIndices.SolarSystemDeserializer.java
/** * Deserialize SolarSystemCost, get value solar_system_id and cost_indices[] from json * @param je/*from w ww. j a v a 2 s.c om*/ * @param type * @param jdc * @return * @throws JsonParseException */ @Override public SolarSystemCost deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { try { JsonObject jsonObject = je.getAsJsonObject(); String solarSystemTemp = jsonObject.get("solar_system_id").getAsString(); CostIndex[] costIndexs = jdc.deserialize(jsonObject.get("cost_indices"), CostIndex[].class); SolarSystemCost solarSystem = new SolarSystemCost(solarSystemTemp, costIndexs); // solarSystem.setSolarSystem(solarSystemTemp); // solarSystem.setCostIndexs(costIndexs); return solarSystem; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:managerindustry.logic.apiEsiJson.skill.characterSkills.SkillsDeserializer.java
@Override public SkillParser deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { try {//from w ww. j av a 2s . c o m JsonObject jsonObject = je.getAsJsonObject(); String total_sp = jsonObject.get("total_sp").getAsString(); SkillRaw[] skillRaws = jdc.deserialize(jsonObject.get("skills"), SkillRaw[].class); SkillParser skill = new SkillParser(skillRaws, total_sp); return skill; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:me.cybermaxke.elementarrows.forge.json.JsonRecipe.java
License:Open Source License
@Override public Recipe deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException { JsonObject json0 = json.getAsJsonObject(); if (json0.has("shape")) { ItemStack result = ctx.deserialize(json0.get("result"), ItemStack.class); String[] shape = ctx.deserialize(json0.get("shape"), String[].class); Map<Character, ItemStack> ingredients = new HashMap<Character, ItemStack>(); for (Entry<String, JsonElement> entry : json0.get("ingredients").getAsJsonObject().entrySet()) { ingredients.put(entry.getKey().charAt(0), (ItemStack) ctx.deserialize(entry.getValue(), ItemStack.class)); }/*from www .j av a 2 s . co m*/ return new RecipeShaped(result, shape, ingredients); } else { ItemStack result = ctx.deserialize(json0.get("result"), ItemStack.class); List<ItemStack> ingredients = new ArrayList<ItemStack>(); JsonArray ingredients0 = json0.get("ingredients").getAsJsonArray(); for (int i = 0; i < ingredients0.size(); i++) { ingredients.add((ItemStack) ctx.deserialize(ingredients0.get(i), ItemStack.class)); } return new RecipeShapeless(result, ingredients); } }
From source file:models.utils.NaturalDeserializer.java
License:Apache License
private Object handleObject(JsonObject json, JsonDeserializationContext context) { Map<String, Object> map = new HashMap<String, Object>(); for (Map.Entry<String, JsonElement> entry : json.entrySet()) map.put(entry.getKey(), context.deserialize(entry.getValue(), NodeData.class)); return map;//from w w w. ja va2 s. c o m }
From source file:net.conquiris.gson.GsonIndexReport.java
License:Apache License
@Override public IndexReport deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { checkArgument(json.isJsonObject(), "Expected JSON Object to deserialize IndexReport."); final JsonObject object = json.getAsJsonObject(); final IndexReportLevel level = IndexReportLevel.valueOf(object.getAsJsonPrimitive(LEVEL).getAsString()); final boolean started = object.getAsJsonPrimitive(STARTED).getAsBoolean(); final boolean active = object.getAsJsonPrimitive(ACTIVE).getAsBoolean(); final IndexStatus status = IndexStatus.valueOf(object.getAsJsonPrimitive(STATUS).getAsString()); if (level == IndexReportLevel.BASIC) { return IndexReport.basic(started, active, status); }//from w w w . j a v a 2s. co m final Delays delays = context.deserialize(object.get(DELAYS), Delays.class); final IndexInfo info = context.deserialize(object.get(INFO), IndexInfo.class); if (level == IndexReportLevel.NORMAL) { return IndexReport.normal(started, active, status, delays, info); } return IndexReport.detailed(started, active, status, delays, info); }