@Override @Nullable public Feature deserialize(@Nonnull JsonElement json, @Nonnull Type typeOfT, @Nonnull JsonDeserializationContext context) throws JsonParseException { try { JsonObject jsonObject = json.getAsJsonObject(); // default path String name = jsonObject.get("name").getAsString(); if (!name.contains(".")) { name = DEFAULT_PATH + "." + name; } Class clazz = Class.forName(name); Feature feature = context.deserialize(json, clazz); injector.injectMembers(feature); return feature; } catch (Exception e) { log.log(Level.WARNING, "Could not deserialize feature:\n" + json.toString(), e); } return null; }
public SetAttributes deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn) { JsonArray jsonarray = JsonUtils.getJsonArray(object, "modifiers"); SetAttributes.Modifier[] asetattributes$modifier = new SetAttributes.Modifier[jsonarray.size()]; int i = 0; for (JsonElement jsonelement : jsonarray) { asetattributes$modifier[i++] = SetAttributes.Modifier.deserialize(JsonUtils.getJsonObject(jsonelement, "modifier"), deserializationContext); } if (asetattributes$modifier.length == 0) { throw new JsonSyntaxException("Invalid attribute modifiers array; cannot be empty"); } else { return new SetAttributes(conditionsIn, asetattributes$modifier); } }
public VariantList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { List<Variant> list = Lists.<Variant>newArrayList(); if (p_deserialize_1_.isJsonArray()) { JsonArray jsonarray = p_deserialize_1_.getAsJsonArray(); if (jsonarray.size() == 0) { throw new JsonParseException("Empty variant array"); } for (JsonElement jsonelement : jsonarray) { list.add((Variant)p_deserialize_3_.deserialize(jsonelement, Variant.class)); } } else { list.add((Variant)p_deserialize_3_.deserialize(p_deserialize_1_, Variant.class)); } return new VariantList(list); }
protected Map<String, VariantList> parseMapVariants(JsonDeserializationContext deserializationContext, JsonObject object) { Map<String, VariantList> map = Maps.<String, VariantList>newHashMap(); if (object.has("variants")) { JsonObject jsonobject = JsonUtils.getJsonObject(object, "variants"); for (Entry<String, JsonElement> entry : jsonobject.entrySet()) { map.put(entry.getKey(), (VariantList)deserializationContext.deserialize((JsonElement)entry.getValue(), VariantList.class)); } } return map; }
@Override public VideoList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { VideoList videoList = new VideoList(); JsonObject jsonObject = json.getAsJsonObject().getAsJsonObject("data"); videoList.setAfter(jsonObject.getAsJsonPrimitive("after").getAsString()); Iterator<JsonElement> videoListJsonIterator = jsonObject.getAsJsonArray("children").iterator(); while (videoListJsonIterator.hasNext()) { JsonElement videoItemJson = videoListJsonIterator.next(); try { Video video = context.deserialize(videoItemJson, Video.class); if (video != null) { videoList.addVideo(video); } } catch (Throwable t) { Log.e(TAG, "Failed to deserialize a video item : " + videoItemJson, t); } } return videoList; }
@Override public Video deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Video video = null; JsonObject jsonObject = json.getAsJsonObject().getAsJsonObject("data"); String domain = jsonObject.getAsJsonPrimitive("domain").getAsString(); if (isYoutubeDomain(domain)) { String url = jsonObject.getAsJsonPrimitive("url").getAsString(); String youtubeId = getYoutubeId(url); if (youtubeId != null && youtubeId.length() > 0) { video = new Video( jsonObject.getAsJsonPrimitive("id").getAsString(), youtubeId, jsonObject.getAsJsonPrimitive("created").getAsLong(), jsonObject.getAsJsonPrimitive("title").getAsString(), url ); } } return video; }
@Override public UserArray deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject root = json.getAsJsonObject(); UserArray dto = new UserArray(); dto.count = optInt(root, "count"); if(root.has("items")){ JsonArray array = root.getAsJsonArray("items"); dto.ids = new int[array.size()]; for(int i = 0; i < array.size(); i++){ dto.ids[i] = array.get(i).getAsJsonObject().get("from_id").getAsInt(); } } else { dto.ids = new int[0]; } return dto; }
@Override public URL deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException { Preconditions.checkNotNull(jsonElement); Preconditions.checkNotNull(type); Preconditions.checkNotNull(context); if (jsonElement.getAsString() == null) { throw new JsonParseException("URL must be a string"); } try { return new URL(jsonElement.getAsString()); } catch (final MalformedURLException e) { throw new JsonParseException(e); } }
@Override public FeatureCollectionDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { FeatureCollectionDto dto = new FeatureCollectionDto(); List<FeatureDto> features = new ArrayList<>(); dto.setFeatures(features); JsonObject asJsonObject = json.getAsJsonObject(); JsonArray jsonArray = asJsonObject.get("features").getAsJsonArray(); if (jsonArray == null) { return dto; } for (int i = 0; i < jsonArray.size(); i++) { JsonObject featureElement = jsonArray.get(i).getAsJsonObject(); FeatureDto geometryDto = context.deserialize(featureElement, FeatureDto.class); features.add(geometryDto); } dto.setBbox(BoundingBoxParser.parseBbox(asJsonObject, context)); return dto; }
protected ModelBlockDefinition.Variants parseVariants(JsonDeserializationContext p_178335_1_, Entry<String, JsonElement> p_178335_2_) { String s = (String)p_178335_2_.getKey(); List<ModelBlockDefinition.Variant> list = Lists.<ModelBlockDefinition.Variant>newArrayList(); JsonElement jsonelement = (JsonElement)p_178335_2_.getValue(); if (jsonelement.isJsonArray()) { for (JsonElement jsonelement1 : jsonelement.getAsJsonArray()) { list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement1, ModelBlockDefinition.Variant.class)); } } else { list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement, ModelBlockDefinition.Variant.class)); } return new ModelBlockDefinition.Variants(s, list); }
@Override public AbstractApplication deserialize(final JsonElement p_jsonElement, final Type p_type, final JsonDeserializationContext p_jsonDeserializationContext) { JsonObject jsonObj = p_jsonElement.getAsJsonObject(); String className = jsonObj.get("m_class").getAsString(); boolean enabled = jsonObj.get("m_enabled").getAsBoolean(); // don't create instance if disabled if (!enabled) { return null; } if (!m_appClass.getSuperclass().equals(AbstractApplication.class)) { // check if there is an "interface"/abstract class between DXRAMComponent and the instance to // create if (!m_appClass.getSuperclass().getSuperclass().equals(AbstractApplication.class)) { LOGGER.fatal("Could class '%s' is not a subclass of AbstractApplication, check your config file", className); return null; } } return p_jsonDeserializationContext.deserialize(p_jsonElement, m_appClass); }
@Override public EntityWrapper deserialize(JsonElement jsonElement, Type typef, JsonDeserializationContext context) throws JsonParseException { if (jsonElement == null || jsonElement instanceof JsonNull) { return null; } JsonObject root = jsonElement.getAsJsonObject(); boolean isNull = root.get(KEY_IS_NULL).getAsBoolean(); Entity entity = null; if (!isNull) { int dbotype = root.get(KEY_TYPE).getAsInt(); entity = context.deserialize(root.get(KEY_ENTITY), AttachmentsTypes.classForType(dbotype)); } return new EntityWrapper(entity); }
@Override public AttachmentsEntity deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { JsonArray array = jsonElement.getAsJsonArray(); if(array.size() == 0){ return new AttachmentsEntity(Collections.emptyList()); } List<Entity> entities = new ArrayList<>(array.size()); for(int i = 0; i < array.size(); i++){ JsonObject o = array.get(i).getAsJsonObject(); int dbotype = o.get(KEY_ENTITY_TYPE).getAsInt(); entities.add(context.deserialize(o.get(KEY_ENTITY), AttachmentsTypes.classForType(dbotype))); } return new AttachmentsEntity(entities); }
@Override public FieldMap deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject rootObject = json.getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = rootObject.entrySet(); FieldMap fieldMap = new FieldMap(); for (Map.Entry<String, JsonElement> entry : entrySet) { JsonObject propertyObject = entry.getValue().getAsJsonObject(); String propertyName = entry.getKey(); parsePropertyObject(propertyObject, propertyName, fieldMap, context); } return fieldMap; }
public ServerStatusResponse.PlayerCountData deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "players"); ServerStatusResponse.PlayerCountData serverstatusresponse$playercountdata = new ServerStatusResponse.PlayerCountData(JsonUtils.getInt(jsonobject, "max"), JsonUtils.getInt(jsonobject, "online")); if (JsonUtils.isJsonArray(jsonobject, "sample")) { JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sample"); if (jsonarray.size() > 0) { GameProfile[] agameprofile = new GameProfile[jsonarray.size()]; for (int i = 0; i < agameprofile.length; ++i) { JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonarray.get(i), "player[" + i + "]"); String s = JsonUtils.getString(jsonobject1, "id"); agameprofile[i] = new GameProfile(UUID.fromString(s), JsonUtils.getString(jsonobject1, "name")); } serverstatusresponse$playercountdata.setPlayers(agameprofile); } } return serverstatusresponse$playercountdata; }
private Retrofit getRetrofitInstance() { if (retrofit == null) { Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { public Date deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { return new Date(json.getAsJsonPrimitive().getAsLong()); } }) .setPrettyPrinting() .create(); retrofit = new Retrofit.Builder() .client(getUnsafeOkHttpClient()) .baseUrl(Constants.GOOGLE_BASE_URL) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); retrofit.client().interceptors().add(new RequestInterceptor()); } return retrofit; }
public static LootEntryItem deserialize(JsonObject object, JsonDeserializationContext deserializationContext, int weightIn, int qualityIn, LootCondition[] conditionsIn) { Item item = JsonUtils.getItem(object, "name"); LootFunction[] alootfunction; if (object.has("functions")) { alootfunction = (LootFunction[])JsonUtils.deserializeClass(object, "functions", deserializationContext, LootFunction[].class); } else { alootfunction = new LootFunction[0]; } return new LootEntryItem(item, weightIn, qualityIn, alootfunction, conditionsIn); }
@Override @Nullable public Phase deserialize(@Nonnull JsonElement json, @Nonnull Type typeOfT, @Nonnull JsonDeserializationContext context) throws JsonParseException { try { JsonObject jsonObject = json.getAsJsonObject(); // default path String name = jsonObject.get("className").getAsString(); Class clazz = Class.forName(name); Phase phase = context.deserialize(json, clazz); injector.injectMembers(phase); return phase; } catch (Exception e) { log.log(Level.WARNING, "Could not deserialize phase:\n" + json.toString(), e); } return null; }
public LootCondition deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "condition"); ResourceLocation resourcelocation = new ResourceLocation(JsonUtils.getString(jsonobject, "condition")); LootCondition.Serializer<?> serializer; try { serializer = LootConditionManager.getSerializerForName(resourcelocation); } catch (IllegalArgumentException var8) { throw new JsonSyntaxException("Unknown condition \'" + resourcelocation + "\'"); } return serializer.deserialize(jsonobject, p_deserialize_3_); }
public LootEntry deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "loot item"); String s = JsonUtils.getString(jsonobject, "type"); int i = JsonUtils.getInt(jsonobject, "weight", 1); int j = JsonUtils.getInt(jsonobject, "quality", 0); LootCondition[] alootcondition; if (jsonobject.has("conditions")) { alootcondition = (LootCondition[])JsonUtils.deserializeClass(jsonobject, "conditions", p_deserialize_3_, LootCondition[].class); } else { alootcondition = new LootCondition[0]; } if ("item".equals(s)) { return LootEntryItem.deserialize(jsonobject, p_deserialize_3_, i, j, alootcondition); } else if ("loot_table".equals(s)) { return LootEntryTable.deserialize(jsonobject, p_deserialize_3_, i, j, alootcondition); } else if ("empty".equals(s)) { return LootEntryEmpty.deserialize(jsonobject, p_deserialize_3_, i, j, alootcondition); } else { throw new JsonSyntaxException("Unknown loot entry type \'" + s + "\'"); } }
@Override public Result deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonObject content = je.getAsJsonObject(); ResultType resultType = jdc.deserialize(content.get("type"), ResultType.class); return jdc.deserialize(content.get(resultType.getName()), resultType.getType()); }
@Override public OverlayTerminationConditionTemplate deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { OverlayTerminationConditionType terminationType = OverlayTerminationConditionType .valueOf(json.getAsJsonObject().get("type").getAsString()); if (terminationType == OverlayTerminationConditionType.TIMER) { return context.deserialize(json, TimerTerminationConditionTemplate.class); } // no converter, otherwise stackoverflow return new GsonBuilder().create().fromJson(json, OverlayTerminationConditionTemplate.class); }
public RandomValueRange deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { if (JsonUtils.isNumber(p_deserialize_1_)) { return new RandomValueRange(JsonUtils.getFloat(p_deserialize_1_, "value")); } else { JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "value"); float f = JsonUtils.getFloat(jsonobject, "min"); float f1 = JsonUtils.getFloat(jsonobject, "max"); return new RandomValueRange(f, f1); } }
@Override public GenericZoneSetting deserialize(JsonElement json, Type type, JsonDeserializationContext context) { TadoSystemType settingType = TadoSystemType.valueOf(json.getAsJsonObject().get("type").getAsString()); if (settingType == TadoSystemType.HEATING) { return context.deserialize(json, HeatingZoneSetting.class); } else if (settingType == TadoSystemType.HOT_WATER) { return context.deserialize(json, HotWaterZoneSetting.class); } else if (settingType == TadoSystemType.AIR_CONDITIONING) { return context.deserialize(json, CoolingZoneSetting.class); } return null; }
private Report parseExecutionReport(JsonObject jsonReport, JsonDeserializationContext context){ ExecutionReport executionReport = new ExecutionReport(); JsonArray testSuiteReportsJson = jsonReport.get("testSuiteReports").getAsJsonArray(); testSuiteReportsJson.forEach(suite -> { Report testSuiteReport = prepareGsonParser().fromJson(suite, TestSuiteReport.class); executionReport.getTestSuiteReports().add((TestSuiteReport) testSuiteReport); }); return setDefaultValues(executionReport, jsonReport); }
public BlockPartFace deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = p_deserialize_1_.getAsJsonObject(); EnumFacing enumfacing = this.parseCullFace(jsonobject); int i = this.parseTintIndex(jsonobject); String s = this.parseTexture(jsonobject); BlockFaceUV blockfaceuv = (BlockFaceUV)p_deserialize_3_.deserialize(jsonobject, BlockFaceUV.class); return new BlockPartFace(enumfacing, i, s, blockfaceuv); }
@Override public Tuple deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!json.isJsonArray()) { throw new JsonParseException("Unexpected JsonElement!"); } JsonArray jsa = (JsonArray) json; Object[] data = new Object[jsa.size()]; jSonUtils util = jSonUtils.getInstance(); for (int i = 0; i < jsa.size(); i++) { data[i] = util.objectFromJson(jsa.get(i), context); } return new Tuple(data); }
@Override public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { return json.getAsFloat(); } catch (Exception e) { TLog.log("FloatJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : "")); return 0F; } }
@Override public VaultEntry deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonObject obj = je.getAsJsonObject(); VaultEntry entry = new VaultEntry( VaultEntryType.values()[obj.get("tp").getAsInt()], new Date(obj.get("ts").getAsLong()), obj.get("v1").getAsDouble(), obj.get("v1").getAsDouble()); entry.setAnnotaionFromJson(obj.get("at").getAsString()); return entry; }
@Override public Date deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException { final StringBuilder patternBuilder = new StringBuilder("yyyy-MM-dd'T'HH:mm:s"); final int strLength = element.getAsString().length(); if(strLength > 18) { final String[] secondsAndMillis = element.getAsString().split("T")[1].split(":")[2].split("\\."); final int secondsDigitCount = secondsAndMillis[0].length(); if(secondsDigitCount > 1) { patternBuilder.append("s"); } if(secondsAndMillis.length > 1) { for(int i = 0; i < secondsAndMillis[1].length(); i++) { patternBuilder.append(i > 0 ? "S" : ".S"); } } } final String pattern = patternBuilder.toString(); final DateFormat format = new SimpleDateFormat(pattern); try { return format.parse(element.getAsString()); } catch (ParseException e) { throw new JsonParseException( String.format("'%s' could not be parsed using pattern '%s'", element.getAsString(), pattern), e); } }
@Override public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { TranslatableComponent component = new TranslatableComponent(); JsonObject object = json.getAsJsonObject(); this.deserialize(object, component, context); component.setTranslate(object.get("translate").getAsString()); if (object.has("with")) { component.setWith(Arrays.asList((BaseComponent[])context.deserialize(object.get("with"), BaseComponent[].class))); } return component; }
@Override public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { return json == null ? null : new Date(json.getAsLong()); } catch (NumberFormatException e) { CrashlyticsWrapper.log(e); e.printStackTrace(); return deserialize12HourDateFormatString(json.getAsString()); } }
@Override public FeatureDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { FeatureDto dto = new FeatureDto(); JsonObject asJsonObject = json.getAsJsonObject(); JsonElement geometryElement = asJsonObject.get("geometry"); if (geometryElement != null) { String typeOfGeometry = geometryElement.getAsJsonObject().get("type").getAsString(); GeoJSONObjectTypeEnum typeEnum = GeoJSONObjectTypeEnum.valueOf(typeOfGeometry); GeometryDto geometryDto = context.deserialize(geometryElement, typeEnum.getDtoClass()); dto.setGeometry(geometryDto); } JsonElement propertiesJsonElement = asJsonObject.get("properties"); if (propertiesJsonElement != null) { dto.setProperties(propertiesJsonElement.toString()); } JsonElement idJsonElement = asJsonObject.get("id"); if (idJsonElement != null) { dto.setId(idJsonElement.getAsString()); } dto.setBbox(BoundingBoxParser.parseBbox(asJsonObject, context)); return dto; }
public ItemTransformVec3f deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = p_deserialize_1_.getAsJsonObject(); Vector3f vector3f = this.parseVector3f(jsonobject, "rotation", ROTATION_DEFAULT); Vector3f vector3f1 = this.parseVector3f(jsonobject, "translation", TRANSLATION_DEFAULT); vector3f1.scale(0.0625F); vector3f1.x = MathHelper.clamp_float(vector3f1.x, -5.0F, 5.0F); vector3f1.y = MathHelper.clamp_float(vector3f1.y, -5.0F, 5.0F); vector3f1.z = MathHelper.clamp_float(vector3f1.z, -5.0F, 5.0F); Vector3f vector3f2 = this.parseVector3f(jsonobject, "scale", SCALE_DEFAULT); vector3f2.x = MathHelper.clamp_float(vector3f2.x, -4.0F, 4.0F); vector3f2.y = MathHelper.clamp_float(vector3f2.y, -4.0F, 4.0F); vector3f2.z = MathHelper.clamp_float(vector3f2.z, -4.0F, 4.0F); return new ItemTransformVec3f(vector3f, vector3f1, vector3f2); }
protected List<ModelBlockDefinition.Variants> parseVariantsList(JsonDeserializationContext p_178334_1_, JsonObject p_178334_2_) { JsonObject jsonobject = JsonUtils.getJsonObject(p_178334_2_, "variants"); List<ModelBlockDefinition.Variants> list = Lists.<ModelBlockDefinition.Variants>newArrayList(); for (Entry<String, JsonElement> entry : jsonobject.entrySet()) { list.add(this.parseVariants(p_178334_1_, entry)); } return list; }
public ModelBlockDefinition.Variant deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException { JsonObject jsonobject = p_deserialize_1_.getAsJsonObject(); String s = this.parseModel(jsonobject); ModelRotation modelrotation = this.parseRotation(jsonobject); boolean flag = this.parseUvLock(jsonobject); int i = this.parseWeight(jsonobject); return new ModelBlockDefinition.Variant(this.makeModelLocation(s), modelrotation, flag, i); }
@Override public Config deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonObject content = je.getAsJsonObject(); Config config = new Config(); JsonArray entries = content.getAsJsonObject("data").getAsJsonArray("entries"); for (JsonElement entry : entries) { JsonObject o = entry.getAsJsonObject(); config.put(o.get("key").getAsString(), o.get("value").getAsString()); } return config; }
@Override public GenericZoneCapabilities deserialize(JsonElement json, Type type, JsonDeserializationContext context) { TadoSystemType settingType = TadoSystemType.valueOf(json.getAsJsonObject().get("type").getAsString()); if (settingType == TadoSystemType.HEATING) { return context.deserialize(json, HeatingCapabilities.class); } else if (settingType == TadoSystemType.AIR_CONDITIONING) { return context.deserialize(json, AirConditioningCapabilities.class); } else if (settingType == TadoSystemType.HOT_WATER) { return context.deserialize(json, HotWaterCapabilities.class); } return null; }
@Override public Date deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws com.google.gson.JsonParseException { for (String format : FORMATS) { try { return new SimpleDateFormat(format).parse(jsonElement.getAsString()); } catch (ParseException e) { // Try next format. } } throw new JsonParseException("Failed to parse " + jsonElement + " to Date."); }
@Override public VKApiComment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject root = json.getAsJsonObject(); VKApiComment dto = new VKApiComment(); dto.id = optInt(root, "id"); dto.from_id = optInt(root, "from_id"); if(dto.from_id == 0){ dto.from_id = optInt(root, "owner_id"); } dto.date = optLong(root, "date"); dto.text = optString(root, "text"); dto.reply_to_user = optInt(root, "reply_to_user"); dto.reply_to_comment = optInt(root, "reply_to_comment"); if(root.has("attachments")){ dto.attachments = context.deserialize(root.get("attachments"), VkApiAttachments.class); } if(root.has("likes")){ JsonObject likesRoot = root.getAsJsonObject("likes"); dto.likes = optInt(likesRoot, "count"); dto.user_likes = optIntAsBoolean(likesRoot, "user_likes"); dto.can_like = optIntAsBoolean(likesRoot, "can_like"); } dto.can_edit = optIntAsBoolean(root, "can_edit"); return dto; }