本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.isArray方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.isArray方法的具体用法?Java JsonNode.isArray怎么用?Java JsonNode.isArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.isArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateAssignProp
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void updateAssignProp(JsonNode props) throws IOException, SQLException, DataAccessException {
String name = props.get("scheme").asText();
JsonNode propNode = props.findPath("properties");
String propString = recProp("prop." + name) + ",";
if (propNode.isArray()) {
for (JsonNode p : propNode) {
propString = propString + p.textValue() + ",";
}
propString = propString.substring(0, propString.length() - 1);
} else if (propNode.isTextual()) {
propString = propString + propNode.textValue();
} else {
Logger.error("passed property neither a list or array");
throw new IllegalArgumentException();
}
chngProp("prop." + name, propString);
}
示例2: evalObject
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void evalObject(ObjectNode source, ObjectNode target, RenderContext context,
ScriptContext scriptContext)
{
final Iterator<Entry<String, JsonNode>> it = source.fields();
while( it.hasNext() )
{
final Entry<String, JsonNode> e = it.next();
final String name = e.getKey();
final JsonNode n = e.getValue();
if( n.isObject() )
{
// recursively handle it
final ObjectNode nt = jsonMapper.createObjectNode();
target.put(name, nt);
evalObject((ObjectNode) n, nt, context, scriptContext);
}
else if( n.isInt() || n.isLong() )
{
target.put(name, n.asInt());
}
else if( n.isFloatingPointNumber() || n.isDouble() )
{
target.put(name, n.asDouble());
}
else if( n.isBoolean() )
{
target.put(name, n.asBoolean());
}
else if( n.isArray() )
{
target.putArray(name).addAll((ArrayNode) n);
}
else
{
// freemarker eval
target.put(name, evaluateMarkUp(context, n.asText(), scriptContext));
}
}
}
示例3: principalOf
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Generates a list of principals from the Principal Json Node
*
* @param principalNodes
* the principal Json to be parsed
* @return a list of principals
*/
private List<Principal> principalOf(JsonNode principalNodes) {
List<Principal> principals = new LinkedList<Principal>();
if (principalNodes.asText().equals("*")) {
principals.add(Principal.All);
return principals;
}
Iterator<Map.Entry<String, JsonNode>> mapOfPrincipals = principalNodes
.fields();
String schema;
JsonNode principalNode;
Entry<String, JsonNode> principal;
Iterator<JsonNode> elements;
while (mapOfPrincipals.hasNext()) {
principal = mapOfPrincipals.next();
schema = principal.getKey();
principalNode = principal.getValue();
if (principalNode.isArray()) {
elements = principalNode.elements();
while (elements.hasNext()) {
principals.add(createPrincipal(schema, elements.next()));
}
} else {
principals.add(createPrincipal(schema, principalNode));
}
}
return principals;
}
示例4: deserialize
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* JsonNode convert into UpdateNotification.
* @param node the "params" node of UpdateNotification JsonNode
*/
private UpdateNotification deserialize(JsonNode node) {
if (node.isArray()) {
if (node.size() == 2) {
return new UpdateNotification(node.get(0).asText(), node.get(1));
}
}
return null;
}
示例5: pathAll
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* PathAll matcher that checks if each element of the final
* result matches the expected result.
*
* @param expectedResult Expected result given by the waiter definition
* @param finalResult Final result of the resource got by the execution
* of the JmesPath expression given by the waiter
* definition
* @return True if all elements of the final result matches
* the expected result, False otherwise
*/
public static boolean pathAll(JsonNode expectedResult, JsonNode finalResult) {
if (finalResult.isNull()) {
return false;
}
if (!finalResult.isArray()) {
throw new RuntimeException("Expected an array");
}
for (JsonNode element : finalResult) {
if (!element.equals(expectedResult)) {
return false;
}
}
return true;
}
示例6: validateFilters
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void validateFilters(JsonNode filtersJson) {
if (filtersJson == null || filtersJson.isNull()) {
throw new IncorrectParameterException("Rule filters are required!");
}
if (!filtersJson.isArray()) {
throw new IncorrectParameterException("Filters json is not an array!");
}
ArrayNode filtersArray = (ArrayNode) filtersJson;
for (int i = 0; i < filtersArray.size(); i++) {
validateComponentJson(filtersArray.get(i), ComponentType.FILTER);
}
}
示例7: parse
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public N parse(String nodeName, JsonNode jsonNode) {
if (jsonNode == null) return null;
// Iterate over node's properties
Iterator<String> fieldNameIterator = jsonNode.fieldNames();
while (fieldNameIterator.hasNext()) {
String fieldName = fieldNameIterator.next();
if (isProperty(fieldName)) {
P property = getProperty(fieldName);
JsonNode propertyNode = jsonNode.get(fieldName);
if (property == null || propertyNode == null) continue;
parseProperty(generator, property, propertyNode);
} else if (isCombinationType(fieldName)) {
JsonNode combinationNode = jsonNode.get(fieldName);
if (combinationNode != null && combinationNode.isArray()) {
JsonSchemaCombinationType type = JsonSchemaCombinationType.get(fieldName);
List<JsonNode> combinationNodes = new ArrayList<>();
Iterator<JsonNode> combinationNodeIterator = combinationNode.elements();
while (combinationNodeIterator.hasNext()) {
combinationNodes.add(combinationNodeIterator.next());
}
generator.combine(type, combinationNodes);
}
}
}
return getNode(nodeName, generator);
}
示例8: list
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static Result list() {
try {
List<Instructor> objects = Instructor.getInstructorsList();
JsonNode jsonObjects = Instructor.jsonInstructorsListSerialization(objects);
if (jsonObjects.isArray()) {
int i = 0;
for (JsonNode object : jsonObjects) {
((ObjectNode)object).put("person", objects.get(i).getPerson().jsonSerialization());
int j = 0;
((ArrayNode)(object.get("allocations"))).removeAll();
for (Allocation allocation : objects.get(i).getAllocations()) {
JsonNode allocationNode = allocation.jsonSerialization();
JsonNode courseSessionNode = allocation.getCourseSession().jsonSerialization();
JsonNode course = allocation.getCourseSession().getCourse().jsonSerialization();
((ObjectNode)courseSessionNode).put("course", course);
((ObjectNode)allocationNode).put("courseSession", courseSessionNode);
((ArrayNode)(object.get("allocations"))).add(allocationNode);
j++;
}
i++;
}
}
return ok(jsonObjects);
}catch(Exception e) {
appLogger.error("Error listing objects",e);
return internalServerError("Error listing objects");
}
}
示例9: resourcesOf
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Generates a list of resources from the Resource Json Node.
*
* @param resourceNodes
* the resource Json node to be parsed.
* @return the list of resources.
*/
private List<Resource> resourcesOf(JsonNode resourceNodes) {
List<Resource> resources = new LinkedList<>();
if (resourceNodes.isArray()) {
for (JsonNode resource : resourceNodes) {
resources.add(new Resource(resource.asText()));
}
} else {
resources.add(new Resource(resourceNodes.asText()));
}
return resources;
}
示例10: convert
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public List<DeviceData> convert(String topic, MqttMessage msg) throws Exception {
String data = new String(msg.getPayload(), StandardCharsets.UTF_8);
log.trace("Parsing json message: {}", data);
if (!filterExpression.isEmpty()) {
try {
log.debug("Data before filtering {}", data);
DocumentContext document = JsonPath.parse(data);
document = JsonPath.parse((Object) document.read(filterExpression));
data = document.jsonString();
log.debug("Data after filtering {}", data);
} catch (RuntimeException e) {
log.debug("Failed to apply filter expression: {}", filterExpression);
throw new RuntimeException("Failed to apply filter expression " + filterExpression);
}
}
JsonNode node = mapper.readTree(data);
List<String> srcList;
if (node.isArray()) {
srcList = new ArrayList<>(node.size());
for (int i = 0; i < node.size(); i++) {
srcList.add(mapper.writeValueAsString(node.get(i)));
}
} else {
srcList = Collections.singletonList(data);
}
return parse(topic, srcList);
}
示例11: getNumberOfEmbeddedAssociations
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public long getNumberOfEmbeddedAssociations(SessionFactory sessionFactory) {
RedisClusterCommands<String, String> connection = getConnection( sessionFactory );
long associationCount = 0;
List<String> keys = connection.keys( "*" );
for ( String key : keys ) {
if ( key.startsWith( AbstractRedisDialect.ASSOCIATIONS ) || key.startsWith( AbstractRedisDialect.IDENTIFIERS ) ) {
continue;
}
String type = connection.type( key );
if ( "string".equalsIgnoreCase( type ) ) {
String value = connection.get( key );
JsonNode jsonNode = fromJSON( value );
for ( JsonNode node : jsonNode ) {
if ( node.isArray() ) {
associationCount++;
}
}
}
}
return associationCount;
}
示例12: findFirstByMarker
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Finds the first log with marker name
*
* @param marker the marker name
* @return the tree node
* @throws IOException Signals that an I/O exception has occurred.
*/
public JsonNode findFirstByMarker(String marker) throws IOException {
JsonNode hits = this.query(String.format("{\"query\": {\"match\": {\"marker.name\": \"%s\"}},\"size\": 1,\"sort\":[{\"message.keyword\":{\"order\":\"asc\"}}]}", marker));
assertNotNull(hits);
if (hits.isArray() && hits.size() > 0) {
return hits.get(0).get("_source");
} else {
return null;
}
}
示例13: calculateList
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static int calculateList(JsonNode node) {
int count = 0;
Iterator<JsonNode> arrayIterator = node.elements();
while (arrayIterator.hasNext()) {
JsonNode element = arrayIterator.next();
if (element.isArray()) {
count += calculateList(element);
} else if (element.isContainerNode()) {
count += calculateDict(element);
}
}
return count;
}
示例14: updateDatasetDeployment
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void updateDatasetDeployment(JsonNode root)
throws Exception {
final JsonNode deployment = root.path("deploymentInfo");
if (deployment.isMissingNode() || !deployment.isArray()) {
throw new IllegalArgumentException(
"Dataset deployment info update error, missing necessary fields: " + root.toString());
}
final Object[] idUrn = findDataset(root);
if (idUrn[0] == null || idUrn[1] == null) {
throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
}
final Integer datasetId = (Integer) idUrn[0];
final String urn = (String) idUrn[1];
ObjectMapper om = new ObjectMapper();
// om.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
for (final JsonNode deploymentInfo : deployment) {
DeploymentRecord record = om.convertValue(deploymentInfo, DeploymentRecord.class);
record.setDatasetId(datasetId);
record.setDatasetUrn(urn);
record.setModifiedTime(System.currentTimeMillis() / 1000);
DEPLOYMENT_WRITER.append(record);
}
// remove old info then insert new info
DEPLOYMENT_WRITER.execute(DELETE_DATASET_DEPLOYMENT_BY_DATASET_ID, new Object[]{datasetId});
DEPLOYMENT_WRITER.insert();
}
示例15: actionsOf
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Generates a list of actions from the Action Json Node.
*
* @param actionNodes
* the action Json node to be parsed.
* @return the list of actions.
*/
private List<Action> actionsOf(JsonNode actionNodes) {
List<Action> actions = new LinkedList<Action>();
if (actionNodes.isArray()) {
for (JsonNode action : actionNodes) {
actions.add(new NamedAction(action.asText()));
}
} else {
actions.add(new NamedAction(actionNodes.asText()));
}
return actions;
}