本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.size方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.size方法的具体用法?Java JsonNode.size怎么用?Java JsonNode.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultSet
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的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: 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);
}
示例3: getDefaultList
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Creates a default value for a list property by:
* <ol>
* <li>Creating a new {@link ArrayList} with the correct generic type
* <li>Using {@link Arrays#asList(Object...)} to initialize the list with
* the correct default values
* </ol>
*
* @param fieldType
* the java type that applies for this field ({@link List} with
* some generic type argument)
* @param node
* the node containing default values for this list
* @return an expression that creates a default value that can be assigned
* to this field
*/
private JExpression getDefaultList(JType fieldType, JsonNode node) {
JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass listImplClass = fieldType.owner().ref(ArrayList.class);
listImplClass = listImplClass.narrow(listGenericType);
JInvocation newListImpl = JExpr._new(listImplClass);
if (node instanceof ArrayNode && node.size() > 0) {
JInvocation invokeAsList = fieldType.owner().ref(Arrays.class).staticInvoke("asList");
for (JsonNode defaultValue : node) {
invokeAsList.arg(getDefaultValue(listGenericType, defaultValue));
}
newListImpl.arg(invokeAsList);
} else if (!ruleFactory.getGenerationConfig().isInitializeCollections()) {
return JExpr._null();
}
return newListImpl;
}
示例4: getStringOrArray
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
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());
}
ObjectMapper mapper = new ObjectMapper();
List<String> list = new ArrayList<>(node.size());
for (int i = 0; i < node.size(); i++) {
try {
list.add(mapper.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;
}
示例5: transToValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* convert into value.
* @param valueNode the BaseType JsonNode
* @param baseType BooleanBaseType or IntegerBaseType or RealBaseType or
* StringBaseType or UuidBaseType
* @return Object the value of JsonNode
*/
public static Object transToValue(JsonNode valueNode, BaseType baseType) {
if (baseType instanceof BooleanBaseType) {
return valueNode.asBoolean();
} else if (baseType instanceof IntegerBaseType) {
return valueNode.asInt();
} else if (baseType instanceof RealBaseType) {
return valueNode.asDouble();
} else if (baseType instanceof StringBaseType) {
return valueNode.asText();
} else if (baseType instanceof UuidBaseType) {
if (valueNode.isArray()) {
if (valueNode.size() == 2) {
if (valueNode.get(0).isTextual()
&& ("uuid".equals(valueNode.get(0).asText()) || "named-uuid"
.equals(valueNode.get(0).asText()))) {
return Uuid.uuid(valueNode.get(1).asText());
}
}
} else {
return new RefTableRow(((UuidBaseType) baseType).getRefTable(), valueNode);
}
}
return null;
}
示例6: getValues
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@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").asText(), 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;
}
示例7: decodeLinkTypeConstraint
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Decodes a link type constraint.
*
* @return link type constraint object.
*/
private Constraint decodeLinkTypeConstraint() {
boolean inclusive = nullIsIllegal(json.get(ConstraintCodec.INCLUSIVE),
ConstraintCodec.INCLUSIVE + ConstraintCodec.MISSING_MEMBER_MESSAGE).asBoolean();
JsonNode types = nullIsIllegal(json.get(ConstraintCodec.TYPES),
ConstraintCodec.TYPES + ConstraintCodec.MISSING_MEMBER_MESSAGE);
if (types.size() < 1) {
throw new IllegalArgumentException(
"types array in link constraint must have at least one value");
}
ArrayList<Link.Type> typesEntries = new ArrayList<>(types.size());
IntStream.range(0, types.size())
.forEach(index ->
typesEntries.add(Link.Type.valueOf(types.get(index).asText())));
return new LinkTypeConstraint(inclusive,
typesEntries.toArray(new Link.Type[types.size()]));
}
示例8: toConnectData
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public SchemaAndValue toConnectData(String topic, byte[] value) {
JsonNode jsonValue;
try {
jsonValue = deserializer.deserialize(topic, value);
} catch (SerializationException e) {
throw new DataException("Converting byte[] to Kafka Connect data failed due to serialization error: ", e);
}
if (enableSchemas && (jsonValue == null || !jsonValue.isObject() || jsonValue.size() != 2 || !jsonValue.has("schema") || !jsonValue.has("payload")))
throw new DataException("JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields." +
" If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration.");
// The deserialized data should either be an envelope object containing the schema and the payload or the schema
// was stripped during serialization and we need to fill in an all-encompassing schema.
if (!enableSchemas) {
ObjectNode envelope = JsonNodeFactory.instance.objectNode();
envelope.set("schema", null);
envelope.set("payload", jsonValue);
jsonValue = envelope;
}
return jsonToConnect(jsonValue);
}
示例9: sock_msg
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public void sock_msg(WebSock sock, String message) {
//log(username + "--> New message: " + message);
try {
JsonNode node = mapper.readTree(message);
JsonNode type = node.get("t");
JsonNode data = node.get("d");
if (type != null) switch (type.textValue()) {
case "b":
for (int i=0; i < data.size(); i++) sock_msg(sock,data.get(i).toString());
break;
case "challenges":
clearIncomingChallenges();
JsonNode in = data.get("in");
if (in.size() > 0) {
log("Challenge received as " + username + ": " + data.toString());
for (int i=0;i<in.size();i++) {
addChallenge(in.get(i).get("id").asText(),in.get(i));
}
for (Connection conn : getConns(username)) updateChallenges(conn,this);
//String id = in.get(0).get("id").asText(); log("ACCEPTING: " + id); acceptChallenge(id);
}
break;
default:
break;
}
}
catch (Exception e) { e.printStackTrace(); }
}
示例10: 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;
}
示例11: assertFactObjectBindings
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void assertFactObjectBindings(List<FactEntity.FactObjectBinding> bindings, String json) throws IOException {
JsonNode node = reader.readTree(json);
assertEquals(bindings.size(), node.size());
for (int i = 0; i < node.size(); i++) {
assertEquals(bindings.get(i).getDirectionValue(), node.get(i).get("direction").asInt());
assertEquals(bindings.get(i).getObjectID().toString(), node.get(i).get("objectID").asText());
}
}
示例12: dataDrivenValidTransactions
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Test
public void dataDrivenValidTransactions() throws Exception {
JsonNode json = new ObjectMapper().readTree(new InputStreamReader(getClass().getResourceAsStream(
"tx_valid.json"), Charsets.UTF_8));
for (JsonNode test : json) {
if (test.isArray() && test.size() == 1 && test.get(0).isTextual())
continue; // This is a comment.
Transaction transaction = null;
try {
Map<TransactionOutPoint, Script> scriptPubKeys = parseScriptPubKeys(test.get(0));
transaction = PARAMS.getDefaultSerializer().makeTransaction(HEX.decode(test.get(1).asText().toLowerCase()));
transaction.verify();
Set<VerifyFlag> verifyFlags = parseVerifyFlags(test.get(2).asText());
for (int i = 0; i < transaction.getInputs().size(); i++) {
TransactionInput input = transaction.getInputs().get(i);
if (input.getOutpoint().getIndex() == 0xffffffffL)
input.getOutpoint().setIndex(-1);
assertTrue(scriptPubKeys.containsKey(input.getOutpoint()));
input.getScriptSig().correctlySpends(transaction, i, scriptPubKeys.get(input.getOutpoint()),
verifyFlags);
}
} catch (Exception e) {
System.err.println(test);
if (transaction != null)
System.err.println(transaction);
throw e;
}
}
}
示例13: startGame
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void startGame(String gid, BingoListener l) {
JsonNode playing = finger().get("nowPlaying");
log ("starting, gid: " + gid);
log("starting, playing: " + playing);
for (int i=0; i<playing.size();i++) {
if (playing.get(i).get("gameId").asText().equals(gid)) {
String opponent = playing.get(i).get("opponent").get("id").asText().toLowerCase(); //lowercase
String color = playing.get(i).get("color").asText();
ChessPlayer newPlayer = new ChessPlayer(playing.get(i).get("fullId").asText(),this,wager,l);
chessplayers.put(gid + username.toLowerCase(),newPlayer);
if (!chessgames.containsKey(gid)) {
log("Creating game: " + username + "-> " + opponent);
if (color.equals("white")) {
chessgames.put(gid,new LichessGame(gid,username,opponent));
}
else chessgames.put(gid,new LichessGame(gid,opponent,username.toLowerCase()));
}
clearIncomingChallenges();
clearOutgoingChallenges();
for (Connection conn : getConns(username)) {
conn.tell("begin_lichess_game", playing.get(i));
conn.tell("game", newPlayer.lastPos);
updateChallenges(conn,this);
//updateLichess(conn);
}
newPlayer.listener.updateCard(newPlayer);
return;
}
}
}
示例14: matchArrayElement
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@VisibleForTesting
MatchType matchArrayElement(JsonNode arrayDatum, Schema schema) {
if (arrayDatum.size() >= 1) {
// We only infer from the first element in the array
return matches(arrayDatum.get(0), schema.getElementType());
} else {
// It may seem odd to return FULL here instead of AMBIGUOUS, but in the context of the document with an empty
// array, it fully matches the array type declared in the schema. Therefore we would not like to favour another
// ambiguous match over this one.
log.debug("No JsonNode array element to match against '{}'", schema.getElementType());
return MatchType.FULL;
}
}
示例15: 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);
}