private static <T> T get(String url, Type type) throws IOException { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); if (con.getResponseCode() == 200) { Reader reader = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8); return GSON.fromJson(reader, type); } return null; } }
@Override public void print(Collection<TableModel> models) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonObject jsonRoot = new JsonObject(); if (file != null) { jsonRoot.add("file", new JsonPrimitive(file.toString())); } models.forEach(model -> { jsonRoot.add(model.name().toLowerCase(), tableToJson(model.table(), gson)); }); gson.toJson(jsonRoot, out); }
@Override protected Void doInBackground(Void... params) { gson = new Gson(); JsonObject result = HttpUtil.getResposeJsonObject(BMA.GeDan.geDan(1, 10)); if (result == null) { return null; } //热门歌单 JsonArray pArray = result.get("content").getAsJsonArray(); if (pArray == null) { return null; } int plen = pArray.size(); for (int i = 0; i < plen; i++) { GedanInfo GedanInfo = gson.fromJson(pArray.get(i), GedanInfo.class); recommendList.add(GedanInfo); } return null; }
private String mockLongPollBody(String notificationsStr) { List<ApolloConfigNotification> oldNotifications = gson.fromJson(notificationsStr, notificationType); List<ApolloConfigNotification> newNotifications = new ArrayList<>(); for (ApolloConfigNotification notification : oldNotifications) { newNotifications .add(new ApolloConfigNotification(notification.getNamespaceName(), notification.getNotificationId() + 1)); } return gson.toJson(newNotifications); }
public static List<ProducerJob> deserialize(String jobs) { if (jobs == null || jobs.trim().isEmpty()) { jobs = "[]"; } JsonArray jobsJson = new JsonParser().parse(jobs).getAsJsonArray(); return new Gson().fromJson(jobsJson, new TypeToken<ArrayList<SimpleProducerJob>>() { }.getType()); }
Reader reader = new InputStreamReader(content); JsonObject json = gson.fromJson(reader, JsonObject.class); JsonElement jsonElement = json.get("rows"); JsonArray array = jsonElement.getAsJsonArray(); for (JsonElement element : array) JsonElement value = element.getAsJsonObject().get("value").getAsJsonObject().get(inverseJoinColumnName); if (value != null)
public void load(String path) { try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); InputStream preferenceStream; try { parser.parse(new InputStreamReader(preferenceStream)).getAsJsonObject(); JsonArray densitiesArray = densitiesObject.get(KEY_DENSITIES).getAsJsonArray(); list = gson.fromJson(densitiesArray, listType); String defaultDensityName = densitiesObject.get(KEY_SOURCE).getAsString(); for (ScreenDensity density : list) { if (density.getName().equals(defaultDensityName)) { JsonElement keepSameDensityElement = densitiesObject.get( KEY_KEEP_SAME_DENSITY_FILE); if (keepSameDensityElement != null) {
private JsonObject initResources(String resourceFilePath) { Type listType = new TypeToken<JsonObject>() { }.getType(); Gson gson = new Gson(); JsonObject testData = gson.fromJson(new InputStreamReader(this.getClass().getResourceAsStream(resourceFilePath)), listType); jsonRecord = testData.get("record").getAsJsonObject(); jsonSchema = testData.get("schema").getAsJsonArray(); WorkUnit workUnit = new WorkUnit(new SourceState(), new Extract(new SourceState(), Extract.TableType.SNAPSHOT_ONLY, "namespace", "dummy_table")); state = new WorkUnitState(workUnit); state.setProp(ConfigurationKeys.CONVERTER_AVRO_TIME_FORMAT, "HH:mm:ss"); state.setProp(ConfigurationKeys.CONVERTER_AVRO_DATE_TIMEZONE, "PST"); return testData; }
kunderaMetadata); String _id = object.get("_id").getAsString(); Reader reader = new InputStreamReader(content); JsonObject jsonObject = gson.fromJson(reader, JsonObject.class); JsonElement rev = jsonObject.get("_rev"); object.add("_rev", rev);
public JsonProvider(String resourcePath) throws IOException { try ( InputStreamReader rd = new InputStreamReader( JsonProvider.class.getResourceAsStream( resourcePath ), Charsets.UTF_8 ) ) { JsonObject obj = new Gson().fromJson( rd, JsonObject.class ); for ( Map.Entry<String, JsonElement> entries : obj.entrySet() ) { translations.put( entries.getKey(), entries.getValue().getAsString() ); } } }
@BeforeClass public static void setUp() { Type listType = new TypeToken<JsonObject>() { }.getType(); Gson gson = new Gson(); JsonObject testData = gson.fromJson( new InputStreamReader(JsonIntermediateToParquetGroupConverter.class.getResourceAsStream(RESOURCE_PATH)), listType); testCases = testData.getAsJsonObject(); SourceState source = new SourceState(); workUnit = new WorkUnitState( source.createWorkUnit(source.createExtract(Extract.TableType.SNAPSHOT_ONLY, "test_namespace", "test_table"))); }
new BufferedReader(new InputStreamReader(response.getEntity().getContent(), ConfigurationKeys.DEFAULT_CHARSET_ENCODING))); String line; return new JsonObject(); JsonElement jsonElement = GSON.fromJson(sb.toString(), JsonElement.class); return jsonElement;
key = ((JsonElement) key).getAsString(); Reader reader = new InputStreamReader(content); JsonObject jsonObject = gson.fromJson(reader, JsonObject.class); if (jsonObject.get(((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName()) == null)
/** * Gets the json from response. * * @param response * the response * @return the json from response * @throws IOException * Signals that an I/O exception has occurred. */ private JsonArray getJsonFromResponse(HttpResponse response) throws IOException { InputStream content = response.getEntity().getContent(); Reader reader = new InputStreamReader(content); JsonObject json = gson.fromJson(reader, JsonObject.class); JsonElement jsonElement = json.get("rows"); return jsonElement == null ? null : jsonElement.getAsJsonArray(); }
@Override public List<WxCpTag> tagGet() throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/list"; String responseContent = get(url, null); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return WxCpGsonBuilder.INSTANCE.create() .fromJson( tmpJsonElement.getAsJsonObject().get("taglist"), new TypeToken<List<WxCpTag>>() { }.getType() ); }
@NonNull public Command parse(@NonNull String json) .fromJson(json, ArchiveHabitsCommand.Record.class) .toCommand(habitList); .fromJson(json, ChangeHabitColorCommand.Record.class) .toCommand(habitList); .fromJson(json, CreateHabitCommand.Record.class) .toCommand(modelFactory, habitList); .fromJson(json, CreateRepetitionCommand.Record.class) .toCommand(habitList); .fromJson(json, DeleteHabitsCommand.Record.class) .toCommand(habitList); .fromJson(json, EditHabitCommand.Record.class) .toCommand(modelFactory, habitList); .fromJson(json, ToggleRepetitionCommand.Record.class) .toCommand(habitList); .fromJson(json, UnarchiveHabitsCommand.Record.class) .toCommand(habitList);
@Override public List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException { String url = "https://api.weixin.qq.com/datacube/getusersummary"; JsonObject param = new JsonObject(); param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate)); param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate)); String responseContent = post(url, param.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserSummary>>() { }.getType()); }
private Map<String, Object> getMetadataFromFile(String artifactId) throws IOException { final String fileToString = FileUtils.readFileToString(metadataFileDest, StandardCharsets.UTF_8); LOGGER.debug(format("Reading metadata from file %s.", metadataFileDest.getAbsolutePath())); final Type type = new TypeToken<Map<String, Object>>() { }.getType(); final Map<String, Map> allArtifactsPerPlugin = new GsonBuilder().create().fromJson(fileToString, type); return allArtifactsPerPlugin.get(artifactId); }
public static MusicDetailInfo getInfo(final String id) { MusicDetailInfo info = null; try { JsonObject jsonObject = HttpUtil.getResposeJsonObject(BMA.Song.songBaseInfo(id).trim()).get("result") .getAsJsonObject().get("items").getAsJsonArray().get(0).getAsJsonObject(); info = MainApplication.gsonInstance().fromJson(jsonObject, MusicDetailInfo.class); } catch (Exception e) { e.printStackTrace(); } return info; }