本文整理了Java中org.codehaus.jackson.node.ArrayNode
类的一些代码示例,展示了ArrayNode
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayNode
类的具体详情如下:
包路径:org.codehaus.jackson.node.ArrayNode
类名称:ArrayNode
[英]Node class that represents Arrays mapped from Json content.
[中]表示从Json内容映射的数组的节点类。
代码示例来源:origin: soabase/exhibitor
@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);
}
代码示例来源:origin: apache/nifi
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;
代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl
/**
* Factory method for constructing an empty JSON Array node
*/
public ArrayNode arrayNode() { return new ArrayNode(this); }
代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl
/**
* Method for setting value of a field to specified String value.
*/
public void add(String v) {
if (v == null) {
addNull();
} else {
_add(textNode(v));
}
}
代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl
/**
* Method for setting value of a field to specified numeric value.
*/
public void add(BigDecimal v) {
if (v == null) {
addNull();
} else {
_add(numberNode(v));
}
}
代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl
/**
* Method that will construct a POJONode and add it at the end
* of this array node.
*/
public void addPOJO(Object value)
{
if (value == null) {
addNull();
} else {
_add(POJONode(value));
}
}
代码示例来源:origin: apache/nifi
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);
代码示例来源:origin: apache/helix
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;
}
}
代码示例来源:origin: eBay/YiDB
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()) {
代码示例来源:origin: org.apache.curator/curator-x-discovery-server
@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);
}
代码示例来源:origin: oVirt/ovirt-engine
@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);
}
代码示例来源:origin: com.ngdata/hbase-indexer-model
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;
}
}
代码示例来源:origin: NGDATA/hbase-indexer
@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);
}
}
代码示例来源:origin: apache/nifi
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;
代码示例来源:origin: rdelbru/SIREn
@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;
}
代码示例来源:origin: com.legsem.legstar/legstar.avro.translator
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;
}
代码示例来源:origin: sirensolutions/siren
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));
}
}
}
代码示例来源:origin: org.apache.eagle/eagle-service-base
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() );
}
代码示例来源:origin: eBay/YiDB
/**
* 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());
}
代码示例来源:origin: gravel-st/gravel
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;
}
内容来源于网络,如有侵权,请联系作者删除!