class EncryptionServiceImpl implements EncryptionService {

    public JsonNode encryptJson(Object plaintextJson, String key, String tenantId) throws IOException {

        JsonNode plaintextNode = createJsonNode(plaintextJson);
        JsonNode encryptNode = plaintextNode.deepCopy();

        List<Attribute> attributesToEncrypt = encryptionPolicyConfiguration.getAttributesForKey(key);
        Map<String, List<Attribute>> typeAttributeMap = encryptionPolicyConfiguration.getTypeAttributeMap(attributesToEncrypt);

        for (String type : typeAttributeMap.keySet()) {
            List<Attribute> attributes = typeAttributeMap.get(type);
            List<String> paths = attributes.stream().map(Attribute::getJsonPath).collect(Collectors.toList());

            JsonNode jsonNode = JacksonUtils.filterJsonNodeForPaths(plaintextNode, paths);

            if(! jsonNode.isEmpty(objectMapper.getSerializerProvider())) {
                JsonNode returnedEncryptedNode = objectMapper.valueToTree(encryptionServiceRestConnection.callEncrypt(tenantId,
                        type, jsonNode));
                encryptNode = JacksonUtils.merge(returnedEncryptedNode, encryptNode);
            }
        }

        return encryptNode;
    }

}