本文整理匯總了Java中com.fasterxml.jackson.databind.node.ArrayNode類的典型用法代碼示例。如果您正苦於以下問題:Java ArrayNode類的具體用法?Java ArrayNode怎麽用?Java ArrayNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ArrayNode類屬於com.fasterxml.jackson.databind.node包,在下文中一共展示了ArrayNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDefaultSet
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
/**
* Creates a default value for a set property by:
* <ol>
* <li>Creating a new {@link LinkedHashSet} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the set with the
* correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link Set} with
* some generic type argument)
* @param node
* the node containing default values for this set
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultSet(JType fieldType, JsonNode node) {
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass setImplClass = fieldType.owner().ref(LinkedHashSet.class);
setImplClass = setImplClass.narrow(setGenericType);
JInvocation newSetImpl = JExpr._new(setImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(setGenericType, defaultValue));
}
newSetImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newSetImpl;
}
示例2: sendSlackImageResponse
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
private void sendSlackImageResponse(ObjectNode json, String s3Key) {
try {
ObjectMapper mapper = new ObjectMapper();
ObjectNode message = mapper.createObjectNode();
ArrayNode attachments = mapper.createArrayNode();
ObjectNode attachment = mapper.createObjectNode();
String emoji = json.get("text").asText();
if (UrlValidator.getInstance().isValid(emoji)) {
attachment.put("title_link", emoji);
emoji = StringUtils.substringAfterLast(emoji, "/");
}
String username = json.get("user_name").asText();
String responseUrl = json.get("response_url").asText();
String slackChannelId = json.get("channel_id").asText();
String imageUrl = String.format("https://s3.amazonaws.com/%s/%s", PROPERTIES.getProperty(S3_BUCKET_NAME), s3Key);
message.put("response_type", "in_channel");
message.put("channel_id", slackChannelId);
attachment.put("title", resolveMessage("slackImageResponse", emoji, username));
attachment.put("fallback", resolveMessage("approximated", emoji));
attachment.put("image_url", imageUrl);
attachments.add(attachment);
message.set("attachments", attachments);
HttpClient client = HttpClientBuilder.create().build();
HttpPost slackResponseReq = new HttpPost(responseUrl);
slackResponseReq.setEntity(new StringEntity(mapper.writeValueAsString(message), ContentType.APPLICATION_JSON));
HttpResponse slackResponse = client.execute(slackResponseReq);
int status = slackResponse.getStatusLine().getStatusCode();
LOG.info("Got {} status from Slack API after sending approximation to response url.", status);
} catch (UnsupportedOperationException | IOException e) {
LOG.error("Exception occured when sending Slack response", e);
}
}
示例3: createItemObject
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
private ObjectNode createItemObject(String collectionUuid, PropBagEx metadata, boolean withAttachment)
{
ObjectNode item = mapper.createObjectNode();
ObjectNode collection = item.objectNode();
collection.put("uuid", collectionUuid);
item.put("collection", collection);
item.put("metadata", metadata.toString());
if( withAttachment )
{
ArrayNode attachments = item.arrayNode();
ObjectNode attachment = item.objectNode();
attachment.put("type", "url");
attachment.put("description", "Google");
attachment.put("url", "http://google.com.au/");
attachment.put("uuid", "uuid:0");
attachments.add(attachment);
item.put("attachments", attachments);
}
return item;
}
示例4: getJsonDependencies
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
public static ArrayNode getJsonDependencies(List<Artifact> artifacts, List<Dependency> directDependencies) {
HashMap<String, String> requirements = new HashMap<String, String>(directDependencies.size());
for (Dependency dep : directDependencies) {
requirements.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion());
}
ObjectMapper mapper = new ObjectMapper();
ArrayNode arrayNode = mapper.createArrayNode();
for (Artifact art : artifacts) {
ObjectNode artNode = depToJsonNode(mapper, art);
String requirement;
requirement = requirements.get(art.getGroupId() + ":" + art.getArtifactId());
// Temporary workaround for transitive dependencies
if (requirement == null){
requirement = art.getVersion();
}
artNode.put("requirement", requirement);
arrayNode.add(artNode);
}
return arrayNode;
}
示例5: encode
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
@Override
public ObjectNode encode(Intent intent, CodecContext context) {
checkNotNull(intent, "Intent cannot be null");
final ObjectNode result = context.mapper().createObjectNode()
.put(TYPE, intent.getClass().getSimpleName())
.put(ID, intent.id().toString())
.put(APP_ID, UrlEscapers.urlPathSegmentEscaper()
.escape(intent.appId().name()));
final ArrayNode jsonResources = result.putArray(RESOURCES);
for (final NetworkResource resource : intent.resources()) {
jsonResources.add(resource.toString());
}
IntentService service = context.getService(IntentService.class);
IntentState state = service.getIntentState(intent.key());
if (state != null) {
result.put(STATE, state.toString());
}
return result;
}
示例6: getGeoLocations
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
@Path("geoloc")
@GET
@Produces("application/json")
public Response getGeoLocations() {
ObjectNode rootNode = mapper.createObjectNode();
ArrayNode devices = mapper.createArrayNode();
ArrayNode hosts = mapper.createArrayNode();
Map<String, ObjectNode> metaUi = TopologyViewMessageHandler.getMetaUi();
for (String id : metaUi.keySet()) {
ObjectNode memento = metaUi.get(id);
if (id.length() > 17 && id.charAt(17) == '/') {
addGeoData(hosts, "id", id, memento);
} else {
addGeoData(devices, "uri", id, memento);
}
}
rootNode.set("devices", devices);
rootNode.set("hosts", hosts);
return Response.ok(rootNode.toString()).build();
}
示例7: json
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
/**
* Translates the given property panel into JSON, for returning
* to the client.
*
* @param pp the property panel model
* @return JSON payload
*/
public static ObjectNode json(PropertyPanel pp) {
ObjectNode result = objectNode()
.put(TITLE, pp.title())
.put(TYPE, pp.typeId())
.put(ID, pp.id());
ObjectNode pnode = objectNode();
ArrayNode porder = arrayNode();
for (PropertyPanel.Prop p : pp.properties()) {
porder.add(p.key());
pnode.put(p.key(), p.value());
}
result.set(PROP_ORDER, porder);
result.set(PROPS, pnode);
ArrayNode buttons = arrayNode();
for (ButtonId b : pp.buttons()) {
buttons.add(b.id());
}
result.set(BUTTONS, buttons);
return result;
}
示例8: processOptions
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
private void processOptions(Question question, ArrayNode node) {
Set<Long> persistedIds = question.getOptions().stream()
.map(MultipleChoiceOption::getId)
.collect(Collectors.toSet());
Set<Long> providedIds = StreamSupport.stream(node.spliterator(), false)
.filter(n -> SanitizingHelper.parse("id", n, Long.class).isPresent())
.map(n -> SanitizingHelper.parse("id", n, Long.class).get())
.collect(Collectors.toSet());
// Updates
StreamSupport.stream(node.spliterator(), false)
.filter(o -> {
Optional<Long> id = SanitizingHelper.parse("id", o, Long.class);
return id.isPresent() && persistedIds.contains(id.get());
}).forEach(o -> updateOption(o, false));
// Removals
question.getOptions().stream()
.filter(o -> !providedIds.contains(o.getId()))
.forEach(this::deleteOption);
// Additions
StreamSupport.stream(node.spliterator(), false)
.filter(o -> !SanitizingHelper.parse("id", o, Long.class).isPresent())
.forEach(o -> createOption(question, o));
}
示例9: readMap
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
@Override
protected Map readMap(MapSchema schema, JsonNode node) {
Preconditions.checkNotNull(schema);
Preconditions.checkNotNull(node);
if (node instanceof ArrayNode) {
return super.readMap(schema, node);
}
Preconditions.checkArgument(node instanceof ObjectNode);
Schema keySchema = schema.getKeySchema();
switch (keySchema.getType()) {
case RECORD:
case MAP:
case LIST:
return super.readMap(schema, node);
}
Map map = Maps.newLinkedHashMap();
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> field = fields.next();
String key = field.getKey();
JsonNode val = field.getValue();
map.put(keyFromString(schema.getKeySchema(), key), getNodeData(schema.getValueSchema(), val));
}
return map;
}
示例10: activate
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
@Activate
public void activate() {
KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(ConfigKey.class, ObjectNode.class, ArrayNode.class,
JsonNodeFactory.class, LinkedHashMap.class,
TextNode.class, BooleanNode.class,
LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class,
NullNode.class);
configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder()
.withSerializer(Serializer.using(kryoBuilder.build()))
.withName("onos-network-configs")
.withRelaxedReadConsistency()
.build();
configs.addListener(listener);
log.info("Started");
}
示例11: diskMetrics
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
/**
* Returns disk metrics of all resources.
*
* @return disk metrics of all resources
* @onos.rsModel DiskMetrics
*/
@GET
@Path("disk_metrics")
@Produces(MediaType.APPLICATION_JSON)
public Response diskMetrics() {
ArrayNode diskNodes = root.putArray("disks");
monitorService.availableResourcesSync(localNodeId, DISK).forEach(name -> {
ObjectNode diskNode = mapper().createObjectNode();
ObjectNode valueNode = mapper().createObjectNode();
metricsStats(monitorService, localNodeId, DISK_METRICS, name, valueNode);
diskNode.put("name", name);
diskNode.set("value", valueNode);
diskNodes.add(diskNode);
});
return ok(root).build();
}
示例12: mapToJsonNonStringKeys
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
@Test
public void mapToJsonNonStringKeys() {
Schema intIntMap = SchemaBuilder.map(Schema.INT32_SCHEMA, Schema.INT32_SCHEMA).build();
Map<Integer, Integer> input = new HashMap<>();
input.put(1, 12);
input.put(2, 15);
JsonNode converted = parse(converter.fromConnectData(TOPIC, intIntMap, input));
validateEnvelope(converted);
assertEquals(parse("{ \"type\": \"map\", \"keys\": { \"type\" : \"int32\", \"optional\": false }, \"values\": { \"type\" : \"int32\", \"optional\": false }, \"optional\": false }"),
converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));
assertTrue(converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME).isArray());
ArrayNode payload = (ArrayNode) converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
assertEquals(2, payload.size());
Set<JsonNode> payloadEntries = new HashSet<>();
for (JsonNode elem : payload)
payloadEntries.add(elem);
assertEquals(new HashSet<>(Arrays.asList(JsonNodeFactory.instance.arrayNode().add(1).add(12),
JsonNodeFactory.instance.arrayNode().add(2).add(15))),
payloadEntries
);
}
示例13: testAuth
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
@Test
public void testAuth() throws Exception {
// Add /credentials.json and /mirrors.json
final ArrayNode credentials = JsonNodeFactory.instance.arrayNode().add(credential);
client.push(projName, Project.REPO_META, Revision.HEAD, TestConstants.AUTHOR, "Add a mirror",
Change.ofJsonUpsert("/credentials.json", credentials),
Change.ofJsonUpsert("/mirrors.json",
"[{" +
" \"type\": \"single\"," +
" \"direction\": \"REMOTE_TO_LOCAL\"," +
" \"localRepo\": \"main\"," +
" \"localPath\": \"/\"," +
" \"remoteUri\": \"" + gitUri + '"' +
"}]")).join();
// Try to perform mirroring to see if authentication works as expected.
mirroringService.mirror().join();
}
示例14: isJsonNodeSubset
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
/**
* Returns true if expected is a subset of returned
*
* This is used for JSON serialiser comparisons. This is taken from
* the 'equals' definition of JsonNode's, but without the length check
* on the list of children nodes, plus location reporting.
*
* @param expected
* @param returned
* @return
*/
protected boolean isJsonNodeSubset(JsonNode expected, JsonNode returned) {
if (returned == null) {
errorDescription = "Returned value is null, expected JSON:\n" + expected.toString();
return false;
}
if (returned == expected) return true;
if (returned.getClass() != expected.getClass()) {
errorDescription = "Returned value class is incorrect, expected JSON: " + expected.toString()
+ ", returned JSON: " + returned.toString();
return false;
}
switch (expected.getNodeType()) {
case ARRAY: return isArrayNodeSubset((ArrayNode)expected, (ArrayNode)returned);
case OBJECT: return isObjectNodeSubset((ObjectNode)expected, (ObjectNode)returned);
default: return isValueEqual((ValueNode)expected, (ValueNode)returned); // Will be a ValueNode subclass
}
}
示例15: process
import com.fasterxml.jackson.databind.node.ArrayNode; //導入依賴的package包/類
@Override
public void process(long sid, ObjectNode payload) {
String srcId = string(payload, SRCID);
ElementId src = elementId(srcId);
String dstId = string(payload, DSTID);
ElementId dst = elementId(dstId);
Device srcDevice = deviceService.getDevice((DeviceId) src);
Device dstDevice = deviceService.getDevice((DeviceId) dst);
TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
.valueOf(srcDevice.annotations().value("lsrId")));
TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
.valueOf(dstDevice.annotations().value("lsrId")));
Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
ObjectNode result = objectNode();
ArrayNode arrayNode = arrayNode();
for (Tunnel tunnel : tunnelSet) {
if (tunnel.type() == MPLS) {
arrayNode.add(tunnel.tunnelId().toString());
}
}
result.putArray(BUFFER_ARRAY).addAll(arrayNode);
sendMessage(PCEWEB_SHOW_TUNNEL, sid, result);
}