本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.at方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.at方法的具体用法?Java JsonNode.at怎么用?Java JsonNode.at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addToArray
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
static JsonNode addToArray(final JsonPointer path, final JsonNode node, final JsonNode value) {
final ArrayNode target = (ArrayNode) node.at(path.head());
final String rawToken = path.last().getMatchingProperty();
if (rawToken.equals(LAST_ARRAY_ELEMENT)) {
target.add(value);
return node;
}
final int size = target.size();
final int index;
try {
index = Integer.parseInt(rawToken);
} catch (NumberFormatException ignored) {
throw new JsonPatchException("not an index: " + rawToken + " (expected: a non-negative integer)");
}
if (index < 0 || index > size) {
throw new JsonPatchException("index out of bounds: " + index +
" (expected: >= 0 && <= " + size + ')');
}
target.insert(index, value);
return node;
}
示例2: ensureParent
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static JsonNode ensureParent(JsonNode node, JsonPointer path, String typeName) {
/*
* Check the parent node: it must exist and be a container (ie an array
* or an object) for the add operation to work.
*/
final JsonPointer parentPath = path.head();
final JsonNode parentNode = node.at(parentPath);
if (parentNode.isMissingNode()) {
throw new JsonPatchException("non-existent " + typeName + " parent: " + parentPath);
}
if (!parentNode.isContainerNode()) {
throw new JsonPatchException(typeName + " parent is not a container: " + parentPath +
" (" + parentNode.getNodeType() + ')');
}
return parentNode;
}
示例3: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
JsonNode apply(final JsonNode node) {
JsonNode source = node.at(from);
if (source.isMissingNode()) {
throw new JsonPatchException("non-existent source path: " + from);
}
if (path.toString().isEmpty()) {
return source;
}
final JsonNode targetParent = ensureTargetParent(node, path);
source = source.deepCopy();
return targetParent.isArray() ? AddOperation.addToArray(path, node, source)
: AddOperation.addToObject(path, node, source);
}
示例4: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
JsonNode apply(final JsonNode node) {
if (path.toString().isEmpty()) {
return MissingNode.getInstance();
}
ensureExistence(node);
final JsonNode parentNode = node.at(path.head());
final String raw = path.last().getMatchingProperty();
if (parentNode.isObject()) {
((ObjectNode) parentNode).remove(raw);
} else {
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
}
return node;
}
示例5: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
JsonNode apply(JsonNode node) {
final JsonNode actual = ensureExistence(node);
if (!EQUIVALENCE.equivalent(actual, oldValue)) {
throw new JsonPatchException("mismatching value at '" + path + "': " +
actual + " (expected: " + oldValue + ')');
}
final JsonNode replacement = newValue.deepCopy();
if (path.toString().isEmpty()) {
return replacement;
}
final JsonNode parent = node.at(path.head());
final String rawToken = path.last().getMatchingProperty();
if (parent.isObject()) {
((ObjectNode) parent).set(rawToken, replacement);
} else {
((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement);
}
return node;
}
示例6: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
JsonNode apply(final JsonNode node) {
ensureExistence(node);
final JsonNode replacement = valueCopy();
if (path.toString().isEmpty()) {
return replacement;
}
final JsonNode parent = node.at(path.head());
final String rawToken = path.last().getMatchingProperty();
if (parent.isObject()) {
((ObjectNode) parent).set(rawToken, replacement);
} else {
((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement);
}
return node;
}
示例7: resolveSchemaForReference
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
static String resolveSchemaForReference(final String specification, final String title, final String reference) {
final JsonNode resolved;
try {
final URL inMemoryUrl = inMemory(specification);
resolved = new JsonReferenceProcessor().process(inMemoryUrl);
} catch (JsonReferenceException | IOException e) {
throw new IllegalStateException("Unable to process JSON references", e);
}
final JsonNode node = resolved.at(reference.substring(1));
final ObjectNode schemaNode = (ObjectNode) node;
schemaNode.put("$schema", "http://json-schema.org/schema#");
schemaNode.put("type", "object");
schemaNode.put("title", title);
return serializeJson(schemaNode);
}
示例8: getSummaryOfJobRun
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Get JobRunSummary jor JobRun
*/
public JobRunSummary getSummaryOfJobRun(JobRunId jobRunId) {
ApiResponse response = this.sendGET(jobRunSummaryTemplate, ImmutableMap.of("jobRunId", jobRunId.toString()));
Optional<HttpResponse> optHttpResponse = response.getOptHttpResponse();
if (!optHttpResponse.isPresent()) {
throw new WebmateApiClientException("Could not get summary of JobRun " + jobRunId + ". Got no response");
}
ObjectMapper om = new ObjectMapper();
try {
JsonNode result = om.readTree(EntityUtils.toString(optHttpResponse.get().getEntity()));
return new JobRunSummary(JobRunState.translateApiString(result.at("/state").asText()), result.at("/failureMessage").asText(""), result.at("/summaryInformation"));
} catch (IOException e) {
throw new WebmateApiClientException("Could not read JobRunSummary", e);
}
}
示例9: ensureExistence
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
JsonNode ensureExistence(JsonNode node) {
final JsonNode found = node.at(path);
if (found.isMissingNode()) {
throw new JsonPatchException("non-existent path: " + path);
}
return found;
}
示例10: applicationDefinition
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@CsapDoc ( notes = {
"Gets the application definition for specified release package ",
"Optional: releasePackage - if not specified, Application.json (root package) will be returned",
"Optional: path - json path in definition. If not specified - the entire definition will be returned"
} , linkTests = {
"Application.json",
"CsAgent definition",
"Release Package",
} , linkGetParams = {
"params=none", "path='/jvms/CsAgent'", "releasePackage=changeMe"
} )
@RequestMapping ( "/application" )
public JsonNode applicationDefinition (
String releasePackage,
String path ) {
if ( releasePackage == null ) {
releasePackage = application.getRootModel().getReleasePackageName();
}
ReleasePackage model = application.getModel( releasePackage );
if ( model == null ) {
ObjectNode managerError = jacksonMapper.createObjectNode();
managerError.put( "error", "Unrecognized package name: " + releasePackage );
managerError.set( "available", packagesWithCluster() );
return managerError;
}
JsonNode results = model.getJsonModelDefinition();
if ( path != null ) {
results = results.at( path );
}
return results;
}
示例11: getTransformedResponse
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Object getTransformedResponse(String appid, InputStream content, ContainerRequestContext ctx) {
if (ctx.getUriInfo().getQueryParameters().containsKey("getRawResponse") ||
StringUtils.containsIgnoreCase(getPath(ctx), "getRawResponse=")) {
return content;
} else {
try {
JsonNode tree = ParaObjectUtils.getJsonMapper().readTree(content);
JsonNode hits = tree.at("/hits/hits");
if (hits.isMissingNode()) {
return tree;
} else {
List<String> keys = new LinkedList<String>();
long count = tree.at("/hits/total").asLong();
for (JsonNode hit : hits) {
String id = hit.get("_id").asText();
keys.add(id);
}
DAO dao = CoreUtils.getInstance().getDao();
Map<String, ParaObject> fromDB = dao.readAll(appid, keys, true);
Map<String, Object> result = new HashMap<>();
result.put("items", fromDB);
result.put("totalHits", count);
return result;
}
} catch (IOException ex) {
logger.error(null, ex);
}
return Collections.emptyMap();
}
}
示例12: addToObject
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
static JsonNode addToObject(final JsonPointer path, final JsonNode node, final JsonNode value) {
final ObjectNode target = (ObjectNode) node.at(path.head());
target.set(path.last().getMatchingProperty(), value);
return node;
}
示例13: settings
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@RequestMapping ( value = "/settings" , produces = MediaType.APPLICATION_JSON_VALUE , method = RequestMethod.GET )
public ObjectNode settings (
@RequestParam ( value = "lifeToEdit" , required = false ) String lifeToEdit ) {
logger.info( "lifeToEdit: {}", lifeToEdit );
if ( lifeToEdit == null ) {
lifeToEdit = Application.getCurrentLifeCycle();
}
csapApp.updateCache( true );
// ReleasePackage serviceModel = csapApp.getModel( hostName, serviceName
// ) ;
// logger.info( "Found model: {}", serviceModel.getReleasePackageName()
// );
JsonNode rootNode = csapApp.getRootModel().getJsonModelDefinition();
ObjectNode settingsNode = (ObjectNode) rootNode.at(
DefinitionParser.buildLifePtr( lifeToEdit ) + "/"
+ DefinitionParser.PARSER_SETTINGS );
JsonNode realtime = settingsNode.at( "/metricsCollectionInSeconds/realTimeMeters" );
if ( !realtime.isMissingNode() && realtime.isArray() ) {
((ArrayNode) realtime).elements().forEachRemaining( realTimeDef -> {
MetricCategory performanceCategory = MetricCategory.parse( realTimeDef );
if ( performanceCategory != MetricCategory.notDefined ) {
if ( performanceCategory == MetricCategory.java ) {
String id = realTimeDef.get( "id" ).asText();
String[] ids = id.split( "\\." );
String[] attributes = ids[1].split( "_" );
if ( attributes.length == 3 ) {
logger.info( "Stripping off port from {}, no longer needed", attributes );
((ObjectNode) realTimeDef).put( "id", id.substring( 0, id.lastIndexOf( "_" ) ) );
}
}
}
} );
}
return settingsNode;
}
示例14: getRawMetaData
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Parses meta data for the given music file. No guessing or reformatting is done.
*
*
* @param file The music file to parse.
* @return Meta data for the file.
*/
@Override
public MetaData getRawMetaData(File file) {
MetaData metaData = new MetaData();
try {
// Use `ffprobe` in the transcode directory if it exists, otherwise let the system sort it out.
String ffprobe;
File inTranscodeDirectory = new File(transcodingService.getTranscodeDirectory(), "ffprobe");
if (inTranscodeDirectory.exists()) {
ffprobe = inTranscodeDirectory.getAbsolutePath();
} else {
ffprobe = "ffprobe";
}
ArrayList<String> command = new ArrayList<>(FFPROBE_OPTIONS.length + 2);
command.add(ffprobe);
command.addAll(Arrays.asList(FFPROBE_OPTIONS));
command.add(file.getAbsolutePath());
Process process = Runtime.getRuntime().exec((String[])command.toArray());
final JsonNode result = objectMapper.readTree(process.getInputStream());
metaData.setDurationSeconds(result.at("/format/duration").asInt());
// Bitrate is in Kb/s
metaData.setBitRate(result.at("/format/bit_rate").asInt() / 1000);
// Find the first (if any) stream that has dimensions and use those.
// 'width' and 'height' are display dimensions; compare to 'coded_width', 'coded_height'.
for (JsonNode stream : result.at("/streams")) {
if (stream.has("width") && stream.has("height")) {
metaData.setWidth(stream.get("width").asInt());
metaData.setHeight(stream.get("height").asInt());
break;
}
}
} catch (Throwable x) {
LOG.warn("Error when parsing metadata in " + file, x);
}
return metaData;
}
示例15: point
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static JsonNode point(JsonNode node, Object... fields) {
String pointer = createJsonPointer(fields);
return node.at(pointer);
}