Refine search
@Path("list") @GET @Produces(MediaType.APPLICATION_JSON) public String getClusterAsJson() throws Exception { InstanceConfig config = context.getExhibitor().getConfigManager().getConfig(); ObjectNode node = JsonNodeFactory.instance.objectNode(); ArrayNode serversNode = JsonNodeFactory.instance.arrayNode(); ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC)); for ( ServerSpec spec : serverList.getSpecs() ) { serversNode.add(spec.getHostname()); } node.put("servers", serversNode); node.put("port", config.getInt(IntConfigs.CLIENT_PORT)); return JsonUtil.writeValueAsString(node); }
protected Object getRawNodeValue(final JsonNode fieldNode, final DataType dataType) throws IOException { if (fieldNode == null || fieldNode.isNull()) { return null; if (fieldNode.isNumber()) { return fieldNode.getNumberValue(); if (fieldNode.isArray()) { final ArrayNode arrayNode = (ArrayNode) fieldNode; final int numElements = arrayNode.size(); final Object[] arrayElements = new Object[numElements]; int count = 0;
/** * Factory method for constructing an empty JSON Array node */ public ArrayNode arrayNode() { return new ArrayNode(this); }
/** * Method for setting value of a field to specified numeric value. */ public void add(BigDecimal v) { if (v == null) { addNull(); } else { _add(numberNode(v)); } }
final ObjectMapper mapper = new ObjectMapper(); final AtomicReference<JsonNode> rootNodeRef = new AtomicReference<>(null); try { if (rootNode.isArray()) { arrayNode = (ArrayNode) rootNode; } else { final JsonNodeFactory nodeFactory = JsonNodeFactory.instance; arrayNode = new ArrayNode(nodeFactory); arrayNode.add(rootNode); for (int i=0; i < arrayNode.size(); i++) { final JsonNode jsonNode = arrayNode.get(i); attributes.put(attributePrefix + ".table", tableName); attributes.put(FRAGMENT_ID.key(), fragmentIdentifier); attributes.put(FRAGMENT_COUNT.key(), String.valueOf(arrayNode.size())); attributes.put(FRAGMENT_INDEX.key(), String.valueOf(i)); FlowFile newFlowFile = copyAttributesToOriginal(session, flowFile, fragmentIdentifier, arrayNode.size()); session.transfer(newFlowFile, REL_ORIGINAL);
private Map<String, JobConfig.Builder> getJobConfigs(ArrayNode root) throws HelixException, IOException { Map<String, JobConfig.Builder> jobConfigsMap = new HashMap<>(); for (Iterator<JsonNode> it = root.getElements(); it.hasNext(); ) { JsonNode job = it.next(); ZNRecord record = null; try { record = toZNRecord(job.toString()); } catch (IOException e) { // Ignore the parse since it could be just simple fields } if (record == null || record.getSimpleFields().isEmpty()) { Map<String, String> cfgMap = OBJECT_MAPPER.readValue(job.toString(), TypeFactory.defaultInstance() .constructMapType(HashMap.class, String.class, String.class)); jobConfigsMap .put(job.get(Properties.id.name()).getTextValue(), JobAccessor.getJobConfig(cfgMap)); } else { jobConfigsMap .put(job.get(Properties.id.name()).getTextValue(), JobAccessor.getJobConfig(record)); } } return jobConfigsMap; } }
ObjectMapper jsonMapper = new ObjectMapper(); JsonNode root = jsonMapper.readTree(inputJsonStream); inputJsonStream.close(); Iterator<String> iter = root.getFieldNames(); while (iter.hasNext()) { String metaType = iter.next(); logger.debug(String.format("Load runtime data of type %s", metaType)); ArrayNode child = (ArrayNode) root.get(metaType); List<JsonNode> loadList = new ArrayList<JsonNode>(); Iterator<JsonNode> instIter = child.getElements(); rawData.put(metaType, loadList); while (instIter.hasNext()) {
@Override public void writeTo(ServiceNames serviceNames, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); for ( String name : serviceNames.getNames() ) { ObjectNode node = mapper.createObjectNode(); node.put("name", name); arrayNode.add(node); } mapper.writer().writeValue(entityStream, arrayNode); }
@BeforeEach public void setUpMockRequest() { ObjectMapper mapper = new ObjectMapper(); ObjectNode mockPluginDef = mapper.createObjectNode(); mockPluginDef.put("foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$ mockPluginDefinitionsArray = mapper.createArrayNode(); mockPluginDefinitionsArray.add(mockPluginDef); when(mockApplicationModeObject.toString()).thenReturn(APPLICATION_MODE); when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_APPLICATION_MODE)).thenReturn(mockApplicationModeObject); when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_PLUGIN_DEFS)).thenReturn(mockPluginDefinitionsArray); }
public List<IndexerDefinitionBuilder> fromJsonBytes(byte [] json) { List<IndexerDefinitionBuilder> builders = new ArrayList<IndexerDefinitionBuilder>(); ArrayNode node; try { node = (ArrayNode) new ObjectMapper().readTree(new ByteArrayInputStream(json)); } catch (IOException e) { throw new RuntimeException("Error parsing indexer definition JSON.", e); } Iterator<JsonNode> it = node.getElements(); while (it.hasNext()) { JsonNode nextNode = it.next(); builders.add(IndexerDefinitionJsonSerDeser.INSTANCE.fromJson((ObjectNode)nextNode)); } return builders; } }
@Override public void writeTo(Collection<IndexerDefinition> indices, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException { ArrayNode array = JsonNodeFactory.instance.arrayNode(); IndexerDefinitionJsonSerDeser converter = IndexerDefinitionJsonSerDeser.INSTANCE; for (IndexerDefinition index : indices) { array.add(converter.toJson(index)); } ObjectMapper objectMapper = new ObjectMapper(); IOUtils.write(objectMapper.writeValueAsBytes(array), outputStream); } }
protected Object convertField(final JsonNode fieldNode, final String fieldName, final DataType desiredType, final boolean dropUnknown) throws IOException, MalformedRecordException { if (fieldNode == null || fieldNode.isNull()) { return null; final Iterator<String> fieldNameItr = fieldNode.getFieldNames(); while (fieldNameItr.hasNext()) { final String childName = fieldNameItr.next(); final JsonNode childNode = fieldNode.get(childName); final Object childValue = convertField(childNode, fieldName, valueType, dropUnknown); map.put(childName, childValue); final int numElements = arrayNode.size(); final Object[] arrayElements = new Object[numElements]; int count = 0;
@Override ObjectNode toJson() { final ObjectNode obj = mapper.createObjectNode(); final ObjectNode node = obj.putObject(NodePropertyParser.NODE_PROPERTY); node.put(QueryPropertyParser.QUERY_PROPERTY, booleanExpression); if (this.hasLevel()) { node.put(LevelPropertyParser.LEVEL_PROPERTY, this.getLevel()); } if (this.hasRange()) { final ArrayNode array = node.putArray(RangePropertyParser.RANGE_PROPERTY); array.add(this.getLowerBound()); array.add(this.getUpperBound()); } if (this.hasBoost()) { node.put(BoostPropertyParser.BOOST_PROPERTY, this.getBoost()); } return obj; }
private ContainerNode buildAvroCompositeType(String avroRecordTypeName, final ArrayNode avroFields, boolean isArray, boolean isOptional) throws Xsd2AvroTranslatorException { ObjectNode avroRecord = buildAvroRecordType(avroRecordTypeName, avroFields); if (isArray) { ObjectNode avroArray = MAPPER.createObjectNode(); avroArray.put("type", "array"); avroArray.put("items", avroRecord); return avroArray; } if (isOptional) { ArrayNode typesArray = MAPPER.createArrayNode(); typesArray.add(avroRecord); typesArray.add("null"); return typesArray; } return avroRecord; }
private JsonNode projection(JsonNode node, String relativePath) { if (relativePath == null || relativePath.length() == 0) { return node; } if (node.isArray()) { ArrayNode arrayNode = mapper.createArrayNode(); Iterator<JsonNode> elementsIterator = ((ArrayNode) node).getElements(); while (elementsIterator.hasNext()) { ObjectNode oNode = mapper.createObjectNode(); oNode.put(lastPartOfPath(relativePath), projection(elementsIterator.next(), relativePath)); arrayNode.add(oNode); } return arrayNode; } else { int firstDotPosition = relativePath.indexOf('.'); if (firstDotPosition == -1) { return node.get(relativePath); } else { return projection(node.get(relativePath.substring(0, firstDotPosition)), relativePath.substring(firstDotPosition + 1)); } } }
private void addTo( ObjectNode resourceNode, String uriPrefix, AbstractResourceMethod srm, String path ){ if(resourceNode.get( uriPrefix ) == null){ ObjectNode inner = JsonNodeFactory.instance.objectNode(); inner.put("path", path); inner.put("methods", JsonNodeFactory.instance.arrayNode()); resourceNode.put( uriPrefix, inner ); } ((ArrayNode) resourceNode.get( uriPrefix ).get("methods")).add( srm.getHttpMethod() ); }
/** * Set query */ @Test public void testProject07() { raptorContext.setAllowFullTableScan(true); raptorContext.setShowDisplayMeta(true); String query = "ApplicationService.(services{@_oid}&&updateStrategies{@_type})"; IQueryResult result = queryService.query(query, raptorContext); ArrayNode display = result.getDisplayMeta(); Assert.assertEquals(2, display.size()); ObjectNode servDisplay = (ObjectNode) display.get(0).get("fields"); Assert.assertEquals(2, servDisplay.size()); ObjectNode usDisplay = (ObjectNode) display.get(1).get("fields"); Assert.assertEquals(2, usDisplay.size()); }
private static Object jsonNodeAsSimpleObject(JsonNode value) { Object o = null; if (value.isTextual()) { o = value.asText(); } else if (value.isArray()) { ArrayList<Object> arrayList = new ArrayList<>(); for (Iterator<JsonNode> iter = ((ArrayNode) value).getElements(); iter .hasNext();) { arrayList.add(jsonNodeAsSimpleObject(iter.next())); } o = arrayList.toArray(); } else if (value.isNull()) { o = null; } else if (value.isObject()) { HashMap<String, Object> map = new HashMap<String, Object>(); final Iterator<Entry<String, JsonNode>> fields = value.getFields(); while (fields.hasNext()) { final Entry<String, JsonNode> next = fields.next(); map.put(next.getKey(), jsonNodeAsSimpleObject(next.getValue())); } o = map; } else throw new RuntimeException("Unknown type: " + value); return o; }