Java Code Examples for com.fasterxml.jackson.core.TreeNode#isArray()

The following examples show how to use com.fasterxml.jackson.core.TreeNode#isArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SortJsonComponent.java    From spring-cloud-openfeign with Apache License 2.0 6 votes vote down vote up
@Override
public Sort deserialize(JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {
	TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
	if (treeNode.isArray()) {
		ArrayNode arrayNode = (ArrayNode) treeNode;
		List<Sort.Order> orders = new ArrayList<>();
		for (JsonNode jsonNode : arrayNode) {
			Sort.Order order = new Sort.Order(
					Sort.Direction.valueOf(jsonNode.get("direction").textValue()),
					jsonNode.get("property").textValue());
			orders.add(order);
		}
		return Sort.by(orders);
	}
	return null;
}
 
Example 2
Source File: OperationHistoryHashMapDeserializer.java    From steem-java-api-wrapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<BigInteger, AppliedOperation> deserialize(JsonParser jsonParser,
        DeserializationContext deserializationContext) throws IOException {

    HashMap<BigInteger, AppliedOperation> result = new HashMap<>();

    ObjectCodec codec = jsonParser.getCodec();
    TreeNode rootNode = codec.readTree(jsonParser);

    if (rootNode.isArray()) {
        for (JsonNode node : (ArrayNode) rootNode) {
            result.put(new BigInteger((node.get(0)).asText()),
                    CommunicationHandler.getObjectMapper().treeToValue(node.get(1), AppliedOperation.class));
        }

        return result;
    }

    throw new IllegalArgumentException("JSON Node is not an array.");
}
 
Example 3
Source File: GuestBloggerPairDeserializer.java    From steem-java-api-wrapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<Pair<AccountName, Long>> deserialize(JsonParser jsonParser,
        DeserializationContext deserializationContext) throws IOException {

    List<Pair<AccountName, Long>> result = new ArrayList<>();

    ObjectCodec codec = jsonParser.getCodec();
    TreeNode rootNode = codec.readTree(jsonParser);

    if (rootNode.isArray()) {
        for (JsonNode node : (ArrayNode) rootNode) {
            // result.put((node.get(0)).asText(), (node.get(0)).asInt());
        }

        return result;
    }

    throw new IllegalArgumentException("JSON Node is not an array.");
}
 
Example 4
Source File: TagUsagePairDeserializer.java    From steem-java-api-wrapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<Pair<String, Long>> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    List<Pair<String, Long>> result = new ArrayList<>();

    ObjectCodec codec = jsonParser.getCodec();
    TreeNode rootNode = codec.readTree(jsonParser);

    if (rootNode.isArray()) {
        for (JsonNode node : (ArrayNode) rootNode) {
            // result.put((node.get(0)).asText(), (node.get(0)).asInt());
        }

        return result;
    }

    throw new IllegalArgumentException("JSON Node is not an array.");
}
 
Example 5
Source File: AccountAuthHashMapDeserializer.java    From steem-java-api-wrapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, Integer> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    HashMap<String, Integer> result = new HashMap<>();

    ObjectCodec codec = jsonParser.getCodec();
    TreeNode rootNode = codec.readTree(jsonParser);

    if (rootNode.isArray()) {
        for (JsonNode node : (ArrayNode) rootNode) {
            result.put((node.get(0)).asText(), (node.get(0)).asInt());
        }

        return result;
    }

    throw new IllegalArgumentException("JSON Node is not an array.");
}
 
Example 6
Source File: PublicKeyHashMapDeserializer.java    From steem-java-api-wrapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<PublicKey, Integer> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    HashMap<PublicKey, Integer> result = new HashMap<>();

    ObjectCodec codec = jsonParser.getCodec();
    TreeNode rootNode = codec.readTree(jsonParser);

    if (rootNode.isArray()) {
        for (JsonNode node : (ArrayNode) rootNode) {
            PublicKey publicKey = new PublicKey((node.get(0)).asText());
            result.put(publicKey, (node.get(0)).asInt());
        }

        return result;
    }

    throw new IllegalArgumentException("JSON Node is not an array.");
}
 
Example 7
Source File: AppliedOperationHashMapDeserializer.java    From steem-java-api-wrapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<UInteger, AppliedOperation> deserialize(JsonParser jsonParser,
        DeserializationContext deserializationContext) throws IOException {

    HashMap<UInteger, AppliedOperation> result = new HashMap<>();

    ObjectCodec codec = jsonParser.getCodec();
    TreeNode rootNode = codec.readTree(jsonParser);

    if (rootNode.isArray()) {
        for (JsonNode node : (ArrayNode) rootNode) {
            result.put(UInteger.valueOf(node.get(0).asLong()),
                    CommunicationHandler.getObjectMapper().treeToValue(node.get(1), AppliedOperation.class));
        }

        return result;
    }

    throw new IllegalArgumentException("JSON Node is not an array.");
}
 
Example 8
Source File: Json.java    From gcp-ingestion with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Read bytes into an {@link ArrayNode}.
 *
 * @exception IOException if {@code data} does not contain a valid json object.
 */
public static ArrayNode readArrayNode(byte[] data) throws IOException {
  // Read data into a tree
  TreeNode root = MAPPER.readTree(data);
  // Check that we have an array, because treeToValue won't
  if (root == null || !root.isArray()) {
    throw new IOException("json value is not an array");
  }
  return (ArrayNode) root;
}
 
Example 9
Source File: JSONParser.java    From Halyard with Apache License 2.0 5 votes vote down vote up
private void hash(TreeNode node) {
    if (node.isArray()) {
        md.update((byte)'l');
        for (int i = 0; i < node.size(); i++) {
            hash(node.get(i));
        }
        md.update((byte)'e');
    } else if (node.isObject()) {
        String[] fieldNames = new String[node.size()];
        Iterator<String> it = node.fieldNames();
        for (int i=0; i< fieldNames.length; i++) {
            fieldNames[i] = it.next();
        }
        Arrays.sort(fieldNames);
        md.update((byte)'d');
        for (String fName : fieldNames) {
            hash(fName);
            hash(node.get(fName));
        }
        md.update((byte)'e');
    } else if (node.isValueNode()) {
        String val = ((JsonNode)node).textValue();
        if (val != null) {
            hash(val);
        }
    } else {
        throw new IllegalArgumentException(node.toString());
    }
}