本文整理汇总了Java中com.fasterxml.jackson.databind.node.ObjectNode.putArray方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectNode.putArray方法的具体用法?Java ObjectNode.putArray怎么用?Java ObjectNode.putArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.node.ObjectNode
的用法示例。
在下文中一共展示了ObjectNode.putArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDeviceTelemetry
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
@Override
public MqttDeliveryFuture onDeviceTelemetry(String deviceName, List<TsKvEntry> telemetry) {
final int msgId = msgIdSeq.incrementAndGet();
log.trace("[{}][{}] Updating device telemetry: {}", deviceName, msgId, telemetry);
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
Map<Long, List<TsKvEntry>> tsMap = telemetry.stream().collect(Collectors.groupingBy(v -> v.getTs()));
ArrayNode deviceNode = node.putArray(deviceName);
tsMap.entrySet().forEach(kv -> {
Long ts = kv.getKey();
ObjectNode tsNode = deviceNode.addObject();
tsNode.put("ts", ts);
ObjectNode valuesNode = tsNode.putObject("values");
kv.getValue().forEach(v -> putToNode(valuesNode, v));
});
final int packSize = telemetry.size();
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
return publishAsync(GATEWAY_TELEMETRY_TOPIC, msg,
token -> {
log.debug("[{}][{}] Device telemetry published to Thingsboard!", msgId, deviceName);
telemetryCount.addAndGet(packSize);
},
error -> log.warn("[{}][{}] Failed to publish device telemetry!", deviceName, msgId, error));
}
示例2: toJson
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
public JsonNode toJson() {
ObjectNode jsonRule = new ObjectMapper().createObjectNode();
jsonRule.put("ETag", this.eTag);
jsonRule.put("Id", this.id);
jsonRule.put("Name", this.name);
jsonRule.put("DateCreated", this.dateCreated);
jsonRule.put("DateModified", this.dateModified);
jsonRule.put("Enabled", this.enabled);
jsonRule.put("Description", this.description);
jsonRule.put("GroupId", this.groupId);
jsonRule.put("Severity", this.severity);
ArrayNode jsonConditions = jsonRule.putArray("Conditions");
for (ConditionServiceModel condition : this.conditions) {
ObjectNode jsonCondition = new ObjectMapper().createObjectNode();
jsonCondition.put("Field", condition.getField());
jsonCondition.put("Operator", condition.getOperator());
jsonCondition.put("Value", condition.getValue());
jsonConditions.add(jsonCondition);
}
return jsonRule;
}
示例3: getDefinitionForAllPackages
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
* Mongo chokes on "." in field names. Arguably not a desirable practice
* anyway
*
* @param definitionNode
* @param location
* @return
*/
public ObjectNode getDefinitionForAllPackages () {
ObjectNode applicationDefinition = jacksonMapper.createObjectNode();
logger.debug( "Definition Folder: {}", getDefinitionFolder() );
File[] definitionFiles = getDefinitionFolder().listFiles();
ArrayNode definitions = applicationDefinition.putArray( "definitions" );
getReleasePackageStream().forEach( releasePackage -> {
ObjectNode item = definitions.addObject();
item.put( "fileName", releasePackage.getReleasePackageFileName() );
try {
item.put( "content", releasePackage.getJsonModelDefinition().toString() );
} catch (Exception e) {
item.put( "content", "Failed to parse:" + e.getMessage() );
logger.error( "Failed to create definition object for upload: {}", CSAP.getCsapFilteredStackTrace( e ) );
}
} );
return applicationDefinition;
}
示例4: encode
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
@Override
public ObjectNode encode(TrafficSelector selector, CodecContext context) {
checkNotNull(selector, "Traffic selector cannot be null");
final ObjectNode result = context.mapper().createObjectNode();
final ArrayNode jsonCriteria = result.putArray(CRITERIA);
if (selector.criteria() != null) {
final JsonCodec<Criterion> criterionCodec =
context.codec(Criterion.class);
for (final Criterion criterion : selector.criteria()) {
jsonCriteria.add(criterionCodec.encode(criterion, context));
}
}
return result;
}
示例5: encode
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
@Override
public ObjectNode encode(Host host, CodecContext context) {
checkNotNull(host, "Host cannot be null");
final JsonCodec<HostLocation> locationCodec =
context.codec(HostLocation.class);
final ObjectNode result = context.mapper().createObjectNode()
.put("id", host.id().toString())
.put("mac", host.mac().toString())
.put("vlan", host.vlan().toString());
final ArrayNode jsonIpAddresses = result.putArray("ipAddresses");
for (final IpAddress ipAddress : host.ipAddresses()) {
jsonIpAddresses.add(ipAddress.toString());
}
result.set("ipAddresses", jsonIpAddresses);
result.set("location", locationCodec.encode(host.location(), context));
return annotate(result, host, context);
}
示例6: getMetricsConfiguriation
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
private ObjectNode getMetricsConfiguriation ( ReleasePackage releasePackage ) {
ObjectNode configJson = jacksonMapper.createObjectNode();
// String type = reqType;
// if (reqType.startsWith("jmx"))
// type = "jmx";
for ( String metricType : lifeCycleSettings()
.getMetricToSecondsMap()
.keySet() ) {
ArrayNode samplesArray = configJson.putArray( metricType );
for ( Integer sampleInterval : lifeCycleSettings()
.getMetricToSecondsMap()
.get( metricType ) ) {
samplesArray.add( sampleInterval );
}
}
return configJson;
}
示例7: ensureJmxStandardCacheInitialized
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
private void ensureJmxStandardCacheInitialized ( Map<String, ObjectNode> jmxResultCacheNode ) {
if ( !jmxResultCacheNode.containsKey( serviceInstance.getServiceName_Port() ) ) {
logger.debug( "Creating jmx results storage for: {}", serviceInstance.getServiceName() );
ObjectNode serviceMetricNode = jacksonMapper.createObjectNode();
serviceMetricNode.putArray( "timeStamp" );
for ( JmxCommonEnum jmxMetric : JmxCommonEnum.values() ) {
// some jvms are not tomcat, so skip tomcat specific metrics
if ( !serviceInstance.isTomcatJarsPresent() && jmxMetric.isTomcatOnly() ) {
continue;
}
String metricFullName = jmxMetric.value + "_"
+ serviceInstance.getServiceName_Port();
serviceMetricNode.putArray( metricFullName );
}
jmxResultCacheNode.put( serviceInstance.getServiceName_Port(),
serviceMetricNode );
}
}
示例8: addSpeaker
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
* Adds BGP speaker to configuration.
*
* @param speaker BGP speaker configuration entry
*/
public void addSpeaker(BgpSpeakerConfig speaker) {
ObjectNode speakerNode = JsonNodeFactory.instance.objectNode();
speakerNode.put(NAME, speaker.name().get());
speakerNode.put(VLAN, speaker.vlan().toString());
speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString()
+ "/" + speaker.connectPoint().port().toString());
ArrayNode peersNode = speakerNode.putArray(PEERS);
for (IpAddress peerAddress: speaker.peers()) {
peersNode.add(peerAddress.toString());
}
ArrayNode speakersArray = bgpSpeakers().isEmpty() ?
initBgpConfiguration() : (ArrayNode) object.get(SPEAKERS);
speakersArray.add(speakerNode);
}
示例9: getState
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
public JsonNode getState() {
ObjectMapper mapper = new ObjectMapper();
ObjectNode state = mapper.createObjectNode();
state.put("name", this.gameClass.getSimpleName());
ArrayNode rooms = state.putArray("rooms");
for (GameRoom room : this.rooms.values()) {
rooms.add(room.getState(false));
}
ArrayNode players = state.putArray("players");
for (GamePlayer player : this.players.values()) {
players.add(player.getState());
}
return state;
}
示例10: getRegionDevices
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
* Returns the set of devices that belong to the specified region.
*
* @param regionId region identifier
* @return 200 OK with set of devices that belong to the specified region
* @onos.rsModel RegionDeviceIds
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{regionId}/devices")
public Response getRegionDevices(@PathParam("regionId") String regionId) {
final RegionId rid = RegionId.regionId(regionId);
final Iterable<DeviceId> deviceIds = regionService.getRegionDevices(rid);
final ObjectNode root = mapper().createObjectNode();
final ArrayNode deviceIdsNode = root.putArray("deviceIds");
deviceIds.forEach(did -> deviceIdsNode.add(did.toString()));
return ok(root).build();
}
示例11: alertsBuilder
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
*
* Add errors to errorList.
*
* @param hostName
* @param errorList
* @param responseFromHostStatusJson
*/
public ObjectNode alertsBuilder ( double alertLevel, String hostName, ObjectNode responseFromHostStatusJson ) {
ObjectNode alertMessages = jacksonMapper.createObjectNode();
ArrayNode errorArray = alertMessages.putArray( Application.VALIDATION_ERRORS );
if ( responseFromHostStatusJson.has( "error" ) ) {
errorArray.add( hostName + ": " + responseFromHostStatusJson
.path( "error" )
.textValue() );
// return result;
return alertMessages;
}
ObjectNode hostStatsNode = (ObjectNode) responseFromHostStatusJson.path( HostKeys.hostStats.jsonId );
if ( hostStatsNode == null ) {
errorArray.add( hostName + ": " + "Host response missing attribute: hostStats" );
// return result;
return alertMessages;
}
alertsForHostCpu( hostStatsNode, hostName, alertLevel, errorArray, alertMessages );
alertsForHostMemory( hostStatsNode, hostName, errorArray, alertMessages );
alertsForHostDisk( hostStatsNode, hostName, alertLevel, errorArray, alertMessages );
ObjectNode serviceHealthCollected = (ObjectNode) responseFromHostStatusJson.path( "services" );
if ( serviceHealthCollected == null ) {
errorArray.add( hostName + ": " + "Host response missing attribute: services" );
// return result;
return alertMessages;
}
alertsForServices( hostName, serviceHealthCollected, errorArray, alertLevel, alertMessages );
return alertMessages;
}
示例12: encodeWaypointConstraint
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
* Encodes a waypoint constraint.
*
* @return JSON ObjectNode representing the constraint
*/
private ObjectNode encodeWaypointConstraint() {
checkNotNull(constraint, "Waypoint constraint cannot be null");
final WaypointConstraint waypointConstraint =
(WaypointConstraint) constraint;
final ObjectNode result = context.mapper().createObjectNode();
final ArrayNode jsonWaypoints = result.putArray("waypoints");
for (DeviceId did : waypointConstraint.waypoints()) {
jsonWaypoints.add(did.toString());
}
return result;
}
示例13: setUsers
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
public static void setUsers(ObjectNode task, String... users)
{
ArrayNode userArray = task.putArray("users");
for( String user : users )
{
userArray.add(user);
}
}
示例14: createWorkflowTask
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
protected ObjectNode createWorkflowTask(String name, boolean allowEditing, String... users)
{
ObjectNode node = mapper.createObjectNode();
node.put("name", name);
node.put("type", "t");
ArrayNode userArray = node.putArray("users");
for( String user : users )
{
userArray.add(user);
}
node.put("allowEditing", allowEditing);
return node;
}
示例15: updateIoCache
import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
private ObjectNode updateIoCache ( boolean isInitialRun ) {
ObjectNode diskActivityReport = jacksonMapper.createObjectNode();
String[] diskTestScript = {
"#!/bin/bash",
"iostat -dm",
"" };
String iostatOutput = "";
try {
iostatOutput = osCommandRunner.runUsingDefaultUser( "diskTest", diskTestScript );
// Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
if ( isInitialRun ) {
logger.info( "Results from {}, \n {}", Arrays.asList( diskTestScript ), iostatOutput );
}
if ( Application.isRunningOnDesktop() ) {
iostatOutput = Application.getContents( new File( getClass()
.getResource( "/linux/ioStatResults.txt" ).getFile() ) );
}
String[] iostatLines = iostatOutput.split( LINE_SEPARATOR );
ArrayNode filteredLines = diskActivityReport.putArray( "filteredOutput" );
int totalDiskReadMb = 0;
int totalDiskWriteMb = 0;
for ( int i = 0; i < iostatLines.length; i++ ) {
String curline = iostatLines[i].replaceAll( "\\s+", " " );
logger.debug( "Processing line: {}", curline );
if ( curline != null && !curline.isEmpty() && curline.matches( csapApp.lifeCycleSettings().getIostatDeviceFilter() ) ) {
filteredLines.add( curline );
String[] fields = curline.split( " " );
if ( fields.length == 6 ) {
totalDiskReadMb += Integer.parseInt( fields[4] );
totalDiskWriteMb += Integer.parseInt( fields[5] );
}
}
}
diskActivityReport.put( "totalDiskReadMb", totalDiskReadMb );
diskActivityReport.put( "totalDiskWriteMb", totalDiskWriteMb );
} catch (Exception e) {
logger.info( "Results from {}, \n {}, \n {}",
Arrays.asList( diskTestScript ), iostatOutput,
CSAP.getCsapFilteredStackTrace( e ) );
}
return diskActivityReport;
}