/** * Get the trace information added so far. */ public static String getTraceInfo() { ArrayNode jsonTraces = JsonUtils.newArrayNode(); for (Trace trace : REQUEST_TO_TRACES_MAP.get(TRACE_ENTRY_THREAD_LOCAL.get()._requestId)) { jsonTraces.add(trace.toJson()); } return jsonTraces.toString(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/schemas") @ApiOperation(value = "List all schema names", notes = "Lists all schema names") public String listSchemaNames() { List<String> schemaNames = _pinotHelixResourceManager.getSchemaNames(); ArrayNode ret = JsonUtils.newArrayNode(); if (schemaNames != null) { for (String schema : schemaNames) { ret.add(schema); } } return ret.toString(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/segments/{tableName}") @ApiOperation(value = "Lists names of all segments of a table", notes = "Lists names of all segment names of a table") public String listAllSegmentNames( @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr) { ArrayNode ret = JsonUtils.newArrayNode(); CommonConstants.Helix.TableType tableType = Constants.validateTableType(tableTypeStr); if (tableTypeStr == null) { ret.add(formatSegments(tableName, CommonConstants.Helix.TableType.OFFLINE)); ret.add(formatSegments(tableName, CommonConstants.Helix.TableType.REALTIME)); } else { ret.add(formatSegments(tableName, tableType)); } return ret.toString(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/segments") @Deprecated public String listAllSegmentNames() throws Exception { FileUploadPathProvider provider = new FileUploadPathProvider(_controllerConf); ArrayNode ret = JsonUtils.newArrayNode(); for (final File file : provider.getBaseDataDir().listFiles()) { final String fileName = file.getName(); if (fileName.equalsIgnoreCase("fileUploadTemp") || fileName.equalsIgnoreCase("schemasTemp")) { continue; } final String url = _controllerConf.generateVipUrl() + "/segments/" + fileName; ret.add(url); } return ret.toString(); }
private String listSegmentMetadataInternal(@Nonnull String tableName, @Nonnull String segmentName, @Nullable CommonConstants.Helix.TableType tableType) { List<String> tableNamesWithType = getExistingTableNamesWithType(tableName, tableType); ArrayNode result = JsonUtils.newArrayNode(); for (String tableNameWithType : tableNamesWithType) { ArrayNode segmentMetaData = getSegmentMetaData(tableNameWithType, segmentName); if (segmentMetaData != null) { result.add(segmentMetaData); } } if (result.size() == 0) { String errorMessage = "Failed to find segment: " + segmentName + " in table: " + tableName; if (tableType != null) { errorMessage += " of type: " + tableType; } throw new ControllerApplicationException(LOGGER, errorMessage, Response.Status.NOT_FOUND); } return result.toString(); }
private String getInstanceToSegmentsMap(@Nonnull String tableName, @Nullable CommonConstants.Helix.TableType tableType) { List<String> tableNamesWithType = getExistingTableNamesWithType(tableName, tableType); ArrayNode result = JsonUtils.newArrayNode(); for (String tableNameWithType : tableNamesWithType) { ObjectNode resultForTable = JsonUtils.newObjectNode(); resultForTable.put(FileUploadPathProvider.TABLE_NAME, tableNameWithType); try { // NOTE: for backward-compatibility, we put serialized map string as the value resultForTable.put("segments", JsonUtils.objectToString(_pinotHelixResourceManager.getServerToSegmentsMap(tableNameWithType))); } catch (JsonProcessingException e) { throw new ControllerApplicationException(LOGGER, "Caught JSON exception while getting instance to segments map for table: " + tableNameWithType, Response.Status.INTERNAL_SERVER_ERROR, e); } result.add(resultForTable); } return result.toString(); }
return ret.toString(); } else { throw new ControllerApplicationException(LOGGER, "Table '" + tableName + "' does not exist",
responses.add(responseOffline); ret.add(JsonUtils.objectToJsonNode(responses)); return ret.toString(); } else if (CommonConstants.Helix.TableType.REALTIME == tableType) { if (helixResourceManager.hasRealtimeTable(tableName)) { toggleSegmentsForTable(segmentsToToggle, tableNameWithType, segmentName, state, helixResourceManager); ret.add(JsonUtils.objectToJsonNode(resourceManagerResponse)); return ret.toString();
private Map path(ArrayNode path) { return ImmutableMap.of( "type", "PATH", "formatter", ImmutableList.of(), "subComponents", ImmutableList.of(), "value", path.toString() ); }
String jsonStr = "{\"response\" : [ { \"id\" : \"1a\", \"name\" : \"foo\"},{ \"id\" : \"1b\",\"name\" : \"bar\" } ]}"; ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(jsonStr); ArrayNode arrayNode = (ArrayNode) node.get("response"); System.out.println(arrayNode); List<Pojo> pojos = mapper.readValue(arrayNode.toString(), new TypeReference<List<Pojo>>() {}); System.out.println(pojos);
private void addJSONArrayToFormSpecificData(ArrayNode jsonArray, EditConfigurationVTwo editConfig) { HashMap<String, Object> data = editConfig.getFormSpecificData(); data.put("existingPageContentUnits", jsonArray.toString()); //Experimenting with putting actual array in data.put("existingPageContentUnitsJSONArray", jsonArray); }
private List<JsonNode> convertJsonArrayToList(ArrayNode arrayNode) { try { return mapper.readValue(arrayNode.toString(), TypeFactory.defaultInstance() .constructCollectionType(List.class, JsonNode.class)); } catch (IOException e) { LOGGER.error("Failed to convert ArrayNode to List<JsonNode>", e); return Collections.emptyList(); } } }
ObjectMapper mapper = new ObjectMapper(); JsonNode parsedJson = mapper.readTree(json); //parse the String or do what you already are doing to deserialize the JSON ArrayNode outerArray = mapper.createArrayNode(); //your outer array ObjectNode outerObject = mapper.createObjectNode(); //the object with the "data" array outerObject.putPOJO("data",parsedJson); outerArray.add(outerObject); System.out.println(outerArray.toString()); //just to confirm everything is working
protected EntityResult updateEntities(ArrayNode entities) throws AtlasServiceException { LOG.debug("Updating entities: {}", entities); ObjectNode response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString()); EntityResult results = extractEntityResult(response); LOG.debug("Update entities returned results: {}", results); return results; }
protected EntityResult updateEntities(ArrayNode entities) throws AtlasServiceException { LOG.debug("Updating entities: {}", entities); ObjectNode response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString()); EntityResult results = extractEntityResult(response); LOG.debug("Update entities returned results: {}", results); return results; }
private String parameterDefault(ObjectNode node, String type, String location, ParseResult result) { String key = "default"; if (type != null && type.equals("array")) { ArrayNode array = getArray(key, node, false, location, result); return array != null ? array.toString() : null; } return getString(key, node, false, location, result); }
ArrayNode arrayNode = (ArrayNode) mapper.readTree(this.getScrape().getScrapetext()); A a = mapper.readValue(arrayNode.get(0), A.class); arrayNode.remove(0); List<B> b = mapper.readValue(arrayNode.toString(), new TypeReference<List<B>>() { });
private void json(Set<Driver> drivers) { ArrayNode result = mapper().createArrayNode(); drivers.forEach(driver -> result.add(jsonForEntity(driver, Driver.class))); print("%s", result.toString()); }
@Override public void jsonColumn(Column column) { try { Value v = jsonParser.parse(buildJsonArray((Object[]) value.getArray()).toString()); to.setJson(column, v); } catch (JsonParseException | SQLException | ClassCastException e) { super.jsonColumn(column); } }
public void setCommonVreProperties(String vreName) { final String prefixedName = vreName + "relation"; edge.property("relation_accepted", true); edge.property(prefixedName + "_accepted", true); edge.property("types", jsnA(jsn("relation"), jsn(prefixedName)).toString()); } }