本文整理了Java中com.fasterxml.jackson.databind.JsonNode.isArray()
方法的一些代码示例,展示了JsonNode.isArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.isArray()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:isArray
暂无
代码示例来源:origin: apache/incubator-druid
private boolean isFlatList(JsonNode list)
{
for (JsonNode obj : list) {
if (obj.isObject() || obj.isArray()) {
return false;
}
}
return true;
}
}
代码示例来源:origin: apache/kafka
private static Object convert(JsonNode value) {
if (value.isArray()) {
List<String> retvalList = new ArrayList<>();
for (JsonNode arrayElement : value)
retvalList.add(arrayElement.asText());
return retvalList;
}
return value.getNodeType() == JsonNodeType.NUMBER ? value.numberValue() : value.asText();
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private String getTypeName(JsonNode node) {
if (node.has("type") && node.get("type").isArray() && node.get("type").size() > 0) {
for (JsonNode jsonNode : node.get("type")) {
String typeName = jsonNode.asText();
if (!typeName.equals("null")) {
return typeName;
}
}
}
if (node.has("type") && node.get("type").isTextual()) {
return node.get("type").asText();
}
return DEFAULT_TYPE_NAME;
}
代码示例来源:origin: prestodb/presto
private List<String> getColumnMetadata(Optional<String> parent, JsonNode propertiesNode)
{
ImmutableList.Builder<String> metadata = ImmutableList.builder();
Iterator<Entry<String, JsonNode>> iterator = propertiesNode.fields();
while (iterator.hasNext()) {
Entry<String, JsonNode> entry = iterator.next();
String key = entry.getKey();
JsonNode value = entry.getValue();
String childKey;
if (parent.isPresent()) {
if (parent.get().isEmpty()) {
childKey = key;
}
else {
childKey = parent.get().concat(".").concat(key);
}
}
else {
childKey = key;
}
if (value.isObject()) {
metadata.addAll(getColumnMetadata(Optional.of(childKey), value));
continue;
}
if (!value.isArray()) {
metadata.add(childKey.concat(":").concat(value.textValue()));
}
}
return metadata.build();
}
代码示例来源:origin: Activiti/Activiti
protected List<String> getActiveValueList(List<String> originalValues, String propertyName, ObjectNode taskElementProperties) {
List<String> activeValues = originalValues;
if (taskElementProperties != null) {
JsonNode overrideValuesNode = taskElementProperties.get(propertyName);
if (overrideValuesNode != null) {
if (overrideValuesNode.isNull() || !overrideValuesNode.isArray() || overrideValuesNode.size() == 0) {
activeValues = null;
} else {
activeValues = new ArrayList<String>();
for (JsonNode valueNode : overrideValuesNode) {
activeValues.add(valueNode.asText());
}
}
}
}
return activeValues;
}
}
代码示例来源:origin: apache/avro
private List<String> getTextProps(String key, Map<String,JsonNode> props,
Token token) throws ParseException {
JsonNode value = props.get(key);
if (!value.isArray())
throw error(key+" property must be array: "+value, token);
List<String> values = new ArrayList<String>();
for (JsonNode n : value)
if (n.isTextual())
values.add(n.textValue());
else
throw error(key+" values must be textual: "+n, token);
return values;
}
代码示例来源:origin: spring-projects/spring-data-redis
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) {
if (!(source instanceof JsonNode)) {
resultMap.put(propertyPrefix, source);
return;
}
JsonNode element = (JsonNode) source;
if (element.isArray()) {
Iterator<JsonNode> nodes = element.elements();
while (nodes.hasNext()) {
JsonNode cur = nodes.next();
if (cur.isArray()) {
this.falttenCollection(propertyPrefix, cur.elements(), resultMap);
}
}
} else if (element.isContainerNode()) {
this.doFlatten(propertyPrefix, element.fields(), resultMap);
} else {
resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value"));
}
}
代码示例来源:origin: auth0/java-jwt
@Override
public <T> List<T> asList(Class<T> tClazz) throws JWTDecodeException {
if (!data.isArray()) {
return null;
}
List<T> list = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
try {
list.add(objectReader.treeToValue(data.get(i), tClazz));
} catch (JsonProcessingException e) {
throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e);
}
}
return list;
}
代码示例来源:origin: knowm/XChange
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
if (node.isTextual()) {
return node.textValue();
} else if (node.isObject()) {
JsonNode allNode = node.get("__all__");
if (allNode != null && allNode.isArray()) {
StringBuffer buf = new StringBuffer();
for (JsonNode msgNode : allNode) {
buf.append(msgNode.textValue());
buf.append(",");
}
return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString();
}
return node.toString();
}
return null;
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private JsonNode resolve(JsonNode tree, List<String> path) {
if (path.isEmpty()) {
return tree;
} else {
String part = path.remove(0);
if (tree.isArray()) {
try {
int index = Integer.parseInt(part);
return resolve(tree.get(index), path);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Not a valid array index: " + part);
}
}
if (tree.has(part)) {
return resolve(tree.get(part), path);
} else {
throw new IllegalArgumentException("Path not present: " + part);
}
}
}
}
代码示例来源:origin: knowm/XChange
@Override
public BitZPublicOrder deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectCodec oc = p.getCodec();
JsonNode node = oc.readTree(p);
if (node.isArray()) {
BigDecimal price = new BigDecimal(node.path(0).asText());
BigDecimal volume = new BigDecimal(node.path(1).asText());
return new BitZPublicOrder(price, volume);
}
return null;
}
}
代码示例来源:origin: Netflix/conductor
private Object extractBody(ClientResponse cr) {
String json = cr.getEntity(String.class);
logger.info(json);
try {
JsonNode node = om.readTree(json);
if (node.isArray()) {
return om.convertValue(node, listOfObj);
} else if (node.isObject()) {
return om.convertValue(node, mapOfObj);
} else if (node.isNumber()) {
return om.convertValue(node, Double.class);
} else {
return node.asText();
}
} catch (IOException jpe) {
logger.error(jpe.getMessage(), jpe);
return json;
}
}
代码示例来源:origin: prestodb/presto
@Override
public RangeBoundValue deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonNode node = jp.getCodec().readTree(jp);
if (node.isNull()) {
return null;
}
else {
List<Object> list;
if (node.isArray()) {
list = new ArrayList<>();
Iterator<JsonNode> iter = node.elements();
while (iter.hasNext()) {
Object v = toValue(iter.next());
list.add(v);
}
}
else {
Object v = toValue(node);
list = ImmutableList.of(v);
}
return new RangeBoundValue(list);
}
}
代码示例来源:origin: auth0/java-jwt
List<String> getStringOrArray(Map<String, JsonNode> tree, String claimName) throws JWTDecodeException {
JsonNode node = tree.get(claimName);
if (node == null || node.isNull() || !(node.isArray() || node.isTextual())) {
return null;
}
if (node.isTextual() && !node.asText().isEmpty()) {
return Collections.singletonList(node.asText());
}
List<String> list = new ArrayList<>(node.size());
for (int i = 0; i < node.size(); i++) {
try {
list.add(objectReader.treeToValue(node.get(i), String.class));
} catch (JsonProcessingException e) {
throw new JWTDecodeException("Couldn't map the Claim's array contents to String", e);
}
}
return list;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* 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;
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
protected GeoJsonMultiLineString doDeserialize(ArrayNode coordinates) {
List<GeoJsonLineString> lines = new ArrayList<GeoJsonLineString>(coordinates.size());
for (JsonNode lineString : coordinates) {
if (lineString.isArray()) {
lines.add(toLineString((ArrayNode) lineString));
}
}
return new GeoJsonMultiLineString(lines);
}
}
代码示例来源:origin: aws/aws-sdk-java
public JsonNode visit(JmesPathFlatten flatten, JsonNode input) throws InvalidTypeException {
JsonNode flattenResult = flatten.getFlattenExpr().accept(this, input);
if (flattenResult.isArray()) {
Iterator<JsonNode> elements = flattenResult.elements();
ArrayNode flattenedArray = ObjectMapperSingleton.getObjectMapper().createArrayNode();
while (elements.hasNext()) {
JsonNode element = elements.next();
if (element != null) {
if (element.isArray()) {
Iterator<JsonNode> inner = element.iterator();
while (inner.hasNext()) {
JsonNode innerElement = inner.next();
if (innerElement != null) {
flattenedArray.add(innerElement);
代码示例来源:origin: twosigma/beakerx
@SuppressWarnings("unchecked")
public static List<List<?>> getValues(BeakerObjectConverter parent, JsonNode n, ObjectMapper mapper) throws IOException {
List<List<?>> values = null;
List<String> classes = null;
if (n.has("types"))
classes = mapper.readValue(n.get("types").toString(), List.class);
if (n.has("values")) {
JsonNode nn = n.get("values");
values = new ArrayList<List<?>>();
if (nn.isArray()) {
for (JsonNode nno : nn) {
if (nno.isArray()) {
ArrayList<Object> val = new ArrayList<Object>();
for (int i = 0; i < nno.size(); i++) {
JsonNode nnoo = nno.get(i);
Object obj = parent.deserialize(nnoo, mapper);
val.add(TableDisplayDeSerializer.getValueForDeserializer(obj, classes != null && classes.size() > i ? classes.get(i) : null));
}
values.add(val);
}
}
}
}
return values;
}
代码示例来源:origin: knowm/XChange
@Override
public KucoinActiveOrder deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonNode root = p.readValueAsTree();
if (root.isArray()) {
Date timestamp = new Date(root.get(0).asLong());
KucoinOrderType orderType = KucoinOrderType.valueOf(root.get(1).asText());
BigDecimal price = root.get(2).decimalValue();
BigDecimal amount = root.get(3).decimalValue();
BigDecimal dealAmount = root.get(4).decimalValue(); // amount already filled
String orderOid = root.get(5).textValue();
return new KucoinActiveOrder(timestamp, orderType, price, amount, dealAmount, orderOid);
} else {
throw new RuntimeException("KucoinDealOrder should have an array as root node!");
}
}
}
代码示例来源:origin: knowm/XChange
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
if (node.isTextual()) {
return node.textValue();
} else if (node.isObject()) {
JsonNode allNode = node.get("__all__");
if (allNode != null && allNode.isArray()) {
StringBuffer buf = new StringBuffer();
for (JsonNode msgNode : allNode) {
buf.append(msgNode.textValue());
buf.append(",");
}
return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString();
}
return node.toString();
}
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!