当前位置: 首页>>代码示例>>Java>>正文


Java JsonNode.hasNonNull方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.hasNonNull方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.hasNonNull方法的具体用法?Java JsonNode.hasNonNull怎么用?Java JsonNode.hasNonNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.hasNonNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: jsonNodeToGoogleAccount

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static GoogleAccount jsonNodeToGoogleAccount(JsonNode person) {
	if (person == null) {
		return null;
	}
	if (person.hasNonNull("id") && person.hasNonNull("emails") && person.get("emails").isArray() && person.get("emails").elements().hasNext() && person.hasNonNull("displayName")) {
		String id = person.get("id").asText();
		JsonNode emailNode = person.get("emails").elements().next();
		String email = emailNode.get("value").asText();
		String displayName = person.get("displayName").asText();
		String imageURL;
		if (person.hasNonNull("image") && person.get("image").hasNonNull("url")) {
			imageURL = person.get("image").get("url").asText();
		} else {
			imageURL = "https://ssl.gstatic.com/accounts/ui/avatar_1x.png";
		}
		return new GoogleAccount(id, email, displayName, imageURL);
	}
	return null;
}
 
开发者ID:sgr-io,项目名称:social-signin,代码行数:20,代码来源:GoogleSignInService.java

示例2: processOvsdbMessage

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Processes an JsonNode message received on the channel.
 *
 * @param jsonNode The OvsdbJsonRpcHandler that received the message
 */
private void processOvsdbMessage(JsonNode jsonNode) {

    log.debug("Handle ovsdb message");

    if (jsonNode.has("result")) {

        log.debug("Handle ovsdb result");
        ovsdbProviderService.processResult(jsonNode);

    } else if (jsonNode.hasNonNull("method")) {

        log.debug("Handle ovsdb request");
        if (jsonNode.has("id")
                && !Strings.isNullOrEmpty(jsonNode.get("id").asText())) {
            ovsdbProviderService.processRequest(jsonNode);
        }

    }
    return;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:OvsdbJsonRpcHandler.java

示例3: handleJsonNodeRequest

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
protected ErrorResolver.JsonError handleJsonNodeRequest(JsonNode node, OutputStream output) throws IOException {
    if (node.hasNonNull(JSON_RPC_METHOD_FIELD_NAME)) {
        checkMethod(node.at(JSON_RPC_METHOD_FIELD_NAME).asText());
    }
    return super.handleJsonNodeRequest(node, output);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:8,代码来源:JsonRpcFilterServer.java

示例4: exploreJsonNode

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Explore the Json document to retrieve valid Key/Value couples.
 *
 * @param prefix        The key prefix to remove
 * @param stringBuilder The buffer to put configuration
 * @param jsonNode      The Json node to explore
 * @since 17.08.21
 */
private void exploreJsonNode(final String prefix, final StringBuilder stringBuilder, final JsonNode jsonNode) {
    for (final JsonNode entry : jsonNode) {
        if (entry.hasNonNull("dir") && entry.get("dir").asBoolean()) {
            this.exploreJsonNode(prefix, stringBuilder, entry.get("nodes"));
        } else if (entry.hasNonNull("value")) {
            if (prefix.isEmpty()) {
                stringBuilder.append(
                    StringUtils.removeFirst(
                        entry.get("key").asText(),
                        "/"
                    ).replace("/", ".")
                );
            } else {
                stringBuilder.append(
                    entry.get("key")
                        .asText()
                        .replace("/" + prefix + "/", "")
                        .replace("/", ".")
                );
            }
            stringBuilder.append(" = ");
            stringBuilder.append(
                entry.get("value").asText()
            );
            stringBuilder.append('\n');
        }
    }
}
 
开发者ID:payintech,项目名称:play-remote-configuration,代码行数:37,代码来源:EtcdProvider.java

示例5: jsonNodeToGateway

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Changes JsonNode Gateway to the Gateway.
 *
 * @param gateway the gateway JsonNode
 * @return gateway
 */
private RouterGateway jsonNodeToGateway(JsonNode gateway) {
    checkNotNull(gateway, JSON_NOT_NULL);
    if (!gateway.hasNonNull("network_id")) {
        throw new IllegalArgumentException("network_id should not be null");
    } else if (gateway.get("network_id").asText().isEmpty()) {
        throw new IllegalArgumentException("network_id should not be empty");
    }
    TenantNetworkId networkId = TenantNetworkId
            .networkId(gateway.get("network_id").asText());

    if (!gateway.hasNonNull("enable_snat")) {
        throw new IllegalArgumentException("enable_snat should not be null");
    } else if (gateway.get("enable_snat").asText().isEmpty()) {
        throw new IllegalArgumentException("enable_snat should not be empty");
    }
    checkArgument(gateway.get("enable_snat").isBoolean(),
                  "enable_snat should be boolean");
    boolean enableSnat = gateway.get("enable_snat").asBoolean();

    if (!gateway.hasNonNull("external_fixed_ips")) {
        throw new IllegalArgumentException("external_fixed_ips should not be null");
    } else if (gateway.get("external_fixed_ips").isNull()) {
        throw new IllegalArgumentException("external_fixed_ips should not be empty");
    }
    Iterable<FixedIp> fixedIpList = jsonNodeToFixedIp(gateway
            .get("external_fixed_ips"));
    RouterGateway gatewayObj = RouterGateway
            .routerGateway(networkId, enableSnat, Sets.newHashSet(fixedIpList));
    return gatewayObj;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:37,代码来源:RouterWebResource.java

示例6: jsonNodeToFixedIp

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Changes JsonNode fixedIp to a collection of the fixedIp.
 *
 * @param fixedIp the allocationPools JsonNode
 * @return a collection of fixedIp
 */
private Iterable<FixedIp> jsonNodeToFixedIp(JsonNode fixedIp) {
    checkNotNull(fixedIp, JSON_NOT_NULL);
    ConcurrentMap<Integer, FixedIp> fixedIpMaps = Maps.newConcurrentMap();
    Integer i = 0;
    for (JsonNode node : fixedIp) {
        if (!node.hasNonNull("subnet_id")) {
            throw new IllegalArgumentException("subnet_id should not be null");
        } else if (node.get("subnet_id").asText().isEmpty()) {
            throw new IllegalArgumentException("subnet_id should not be empty");
        }
        SubnetId subnetId = SubnetId
                .subnetId(node.get("subnet_id").asText());
        if (!node.hasNonNull("ip_address")) {
            throw new IllegalArgumentException("ip_address should not be null");
        } else if (node.get("ip_address").asText().isEmpty()) {
            throw new IllegalArgumentException("ip_address should not be empty");
        }
        IpAddress ipAddress = IpAddress
                .valueOf(node.get("ip_address").asText());
        FixedIp fixedIpObj = FixedIp.fixedIp(subnetId, ipAddress);

        fixedIpMaps.putIfAbsent(i, fixedIpObj);
        i++;
    }
    return Collections.unmodifiableCollection(fixedIpMaps.values());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:33,代码来源:RouterWebResource.java

示例7: deserialize

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public SimpleReport deserialize(JsonParser parser, DeserializationContext ctx) throws IOException {
  JsonNode node = parser.getCodec().readTree(parser);
  SimpleReport report = new SimpleReport();

  if (node.hasNonNull(SimpleReport.KEY_CONFIG_APP)) {
    final AppConfiguration config =
        ctx.readValue(node.get(SimpleReport.KEY_CONFIG_APP).traverse(parser.getCodec()), AppConfiguration.class);
    report.put(SimpleReport.KEY_CONFIG_APP, config);
  }

  if (node.hasNonNull(SimpleReport.KEY_CONFIG_CONTROLLER)) {
    final Controller controller =
        ctx.readValue(node.get(SimpleReport.KEY_CONFIG_CONTROLLER)
            .traverse(parser.getCodec()), Controller.class);
    report.put(SimpleReport.KEY_CONFIG_CONTROLLER, controller);
  }

  if (node.hasNonNull(SimpleReport.KEY_ATTACKS)) {
    List<HttpFloodAttack> httpAttacks = new ArrayList<>();
    Iterator<JsonNode> iter = node.get(SimpleReport.KEY_ATTACKS).elements();
    while (iter.hasNext()) {
      JsonNode n = iter.next();
      HttpFloodAttack attack = ctx.readValue(n.traverse(parser.getCodec()), HttpFloodAttack.class);
      httpAttacks.add(attack);
    }
    report.put(SimpleReport.KEY_ATTACKS, httpAttacks);
  }

  node.fields().forEachRemaining(f -> {
    if (!f.getKey().equals(SimpleReport.KEY_CONFIG_APP) &&
        !f.getKey().equals(SimpleReport.KEY_CONFIG_CONTROLLER) &&
        !f.getKey().equals(SimpleReport.KEY_ATTACKS)) {
      report.put(f.getKey(), f.getValue().asText());
    }
  });

  return report;
}
 
开发者ID:braineering,项目名称:ares,代码行数:40,代码来源:SimpleReportDeserializer.java

示例8: loadConfiguration

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Config loadConfiguration(final Mode mode, final Config localConfig) throws IOException {
    final StringBuilder stringBuilder = new StringBuilder(1024);
    final String consulAccessToken = localConfig.getString("remote-configuration.consul.authToken");
    String consulEndpoint = localConfig.getString("remote-configuration.consul.endpoint");
    String consulPrefix = localConfig.getString("remote-configuration.consul.prefix").trim();
    if (consulEndpoint != null && consulEndpoint.startsWith("http")) {
        if (!consulEndpoint.endsWith("/")) {
            consulEndpoint += "/";
        }
        if (consulPrefix.endsWith("/")) {
            consulPrefix = consulPrefix.substring(0, consulPrefix.length() - 1);
        }
        if (consulPrefix.startsWith("/")) {
            consulPrefix = consulPrefix.substring(1, consulPrefix.length());
        }
        InputStream is = null;
        try {
            final URL consulUrl = new URL(
                String.format(
                    "%sv1/kv/%s/?recurse&token=%s",
                    consulEndpoint,
                    consulPrefix,
                    consulAccessToken
                )
            );
            Logger.debug("Provider {}> {}", this.getName(), consulUrl.toString());
            final HttpURLConnection conn = (HttpURLConnection) consulUrl.openConnection();
            conn.setConnectTimeout(1500);
            if (conn.getResponseCode() / 100 == 2) {
                is = conn.getInputStream();
                final ObjectMapper mapper = new ObjectMapper();
                final JsonNode jsonDocument = mapper.readTree(is);
                final Base64.Decoder decoder = Base64.getDecoder();
                for (final JsonNode entry : jsonDocument) {
                    if (entry.hasNonNull("Value")) {
                        stringBuilder.append(
                            entry.get("Key")
                                .asText()
                                .replace(consulPrefix.isEmpty() ? "" : consulPrefix + "/", "")
                                .replace("/", ".")
                        );
                        stringBuilder.append(" = ");
                        stringBuilder.append(
                            new String(
                                decoder.decode(
                                    entry.get("Value").asText()
                                )
                            )
                        );
                        stringBuilder.append('\n');
                    }
                }
            } else {
                Logger.warn("Provider {} return non 200 status: {}", this.getName(), conn.getResponseCode());
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (final IOException ignore) {
                }
            }
        }
    } else {
        throw new RuntimeException("Bad configuration");
    }
    return ConfigFactory.parseString(stringBuilder.toString());
}
 
开发者ID:payintech,项目名称:play-remote-configuration,代码行数:70,代码来源:ConsulProvider.java

示例9: changeJsonToSubs

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Returns a collection of subnets from subnetNodes.
 *
 * @param subnetNodes the subnet json node
 * @return subnets a collection of subnets
 */
public Iterable<Subnet> changeJsonToSubs(JsonNode subnetNodes) {
    checkNotNull(subnetNodes, JSON_NOT_NULL);
    Map<SubnetId, Subnet> subMap = new HashMap<>();
    for (JsonNode subnetNode : subnetNodes) {
        if (!subnetNode.hasNonNull("id")) {
            return null;
        }
        SubnetId id = SubnetId.subnetId(subnetNode.get("id").asText());
        String subnetName = subnetNode.get("name").asText();
        TenantId tenantId = TenantId
                .tenantId(subnetNode.get("tenant_id").asText());
        TenantNetworkId networkId = TenantNetworkId
                .networkId(subnetNode.get("network_id").asText());
        String version = subnetNode.get("ip_version").asText();
        Version ipVersion;
        switch (version) {
        case "4":
            ipVersion = Version.INET;
            break;
        case "6":
            ipVersion = Version.INET;
            break;
        default:
            throw new IllegalArgumentException("ipVersion should be 4 or 6.");
        }
        IpPrefix cidr = IpPrefix.valueOf(subnetNode.get("cidr").asText());
        IpAddress gatewayIp = IpAddress
                .valueOf(subnetNode.get("gateway_ip").asText());
        Boolean dhcpEnabled = subnetNode.get("enable_dhcp").asBoolean();
        Boolean shared = subnetNode.get("shared").asBoolean();
        JsonNode hostRoutes = subnetNode.get("host_routes");
        Iterable<HostRoute> hostRoutesIt = jsonNodeToHostRoutes(hostRoutes);
        JsonNode allocationPools = subnetNode.get("allocation_pools");
        Iterable<AllocationPool> allocationPoolsIt = jsonNodeToAllocationPools(allocationPools);
        Mode ipV6AddressMode = Mode
                .valueOf(subnetNode.get("ipv6_address_mode").asText());
        Mode ipV6RaMode = Mode
                .valueOf(subnetNode.get("ipv6_ra_mode").asText());
        Subnet subnet = new DefaultSubnet(id, subnetName, networkId,
                                          tenantId, ipVersion, cidr,
                                          gatewayIp, dhcpEnabled, shared,
                                          Sets.newHashSet(hostRoutesIt), ipV6AddressMode,
                                          ipV6RaMode, Sets.newHashSet(allocationPoolsIt));
        subMap.put(id, subnet);
    }
    return Collections.unmodifiableCollection(subMap.values());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:54,代码来源:SubnetWebResource.java

示例10: changeJsonToSub

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Returns a collection of subnets from subnetNodes.
 *
 * @param subnetNodes the subnet json node
 * @return subnets a collection of subnets
 */
public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) {
    checkNotNull(subnetNodes, JSON_NOT_NULL);
    checkArgument(subnetNodes.get("enable_dhcp").isBoolean(), "enable_dhcp should be boolean");
    checkArgument(subnetNodes.get("shared").isBoolean(), "shared should be boolean");
    Map<SubnetId, Subnet> subMap = new HashMap<>();
    if (!subnetNodes.hasNonNull("id")) {
        return null;
    }
    SubnetId id = SubnetId.subnetId(subnetNodes.get("id").asText());
    String subnetName = subnetNodes.get("name").asText();
    TenantId tenantId = TenantId
            .tenantId(subnetNodes.get("tenant_id").asText());
    TenantNetworkId networkId = TenantNetworkId
            .networkId(subnetNodes.get("network_id").asText());
    String version = subnetNodes.get("ip_version").asText();
    Version ipVersion;
    switch (version) {
    case "4":
        ipVersion = Version.INET;
        break;
    case "6":
        ipVersion = Version.INET;
        break;
    default:
        throw new IllegalArgumentException("ipVersion should be 4 or 6.");
    }

    IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText());
    IpAddress gatewayIp = IpAddress
            .valueOf(subnetNodes.get("gateway_ip").asText());
    Boolean dhcpEnabled = subnetNodes.get("enable_dhcp").asBoolean();
    Boolean shared = subnetNodes.get("shared").asBoolean();
    JsonNode hostRoutes = subnetNodes.get("host_routes");
    Iterable<HostRoute> hostRoutesIt = jsonNodeToHostRoutes(hostRoutes);
    JsonNode allocationPools = subnetNodes.get("allocation_pools");
    Iterable<AllocationPool> allocationPoolsIt = jsonNodeToAllocationPools(allocationPools);

    Mode ipV6AddressMode = getMode(subnetNodes.get("ipv6_address_mode")
            .asText());
    Mode ipV6RaMode = getMode(subnetNodes.get("ipv6_ra_mode").asText());

    Subnet subnet = new DefaultSubnet(id, subnetName, networkId, tenantId,
                                      ipVersion, cidr, gatewayIp,
                                      dhcpEnabled, shared, Sets.newHashSet(hostRoutesIt),
                                      ipV6AddressMode, ipV6RaMode,
                                      Sets.newHashSet(allocationPoolsIt));
    subMap.put(id, subnet);
    return Collections.unmodifiableCollection(subMap.values());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:56,代码来源:SubnetWebResource.java

示例11: addRouterInterface

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@PUT
@Path("{routerUUID}/add_router_interface")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response addRouterInterface(@PathParam("routerUUID") String id,
                                   final InputStream input) {
    if (!get(RouterService.class).exists(RouterId.valueOf(id))) {
        return Response.status(NOT_FOUND).entity(NOT_EXIST).build();
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode subnode = mapper.readTree(input);
        if (!subnode.hasNonNull("id")) {
            throw new IllegalArgumentException("id should not be null");
        } else if (subnode.get("id").asText().isEmpty()) {
            throw new IllegalArgumentException("id should not be empty");
        }
        RouterId routerId = RouterId.valueOf(id);
        if (!subnode.hasNonNull("subnet_id")) {
            throw new IllegalArgumentException("subnet_id should not be null");
        } else if (subnode.get("subnet_id").asText().isEmpty()) {
            throw new IllegalArgumentException("subnet_id should not be empty");
        }
        SubnetId subnetId = SubnetId
                .subnetId(subnode.get("subnet_id").asText());
        if (!subnode.hasNonNull("tenant_id")) {
            throw new IllegalArgumentException("tenant_id should not be null");
        } else if (subnode.get("tenant_id").asText().isEmpty()) {
            throw new IllegalArgumentException("tenant_id should not be empty");
        }
        TenantId tenentId = TenantId
                .tenantId(subnode.get("tenant_id").asText());
        if (!subnode.hasNonNull("port_id")) {
            throw new IllegalArgumentException("port_id should not be null");
        } else if (subnode.get("port_id").asText().isEmpty()) {
            throw new IllegalArgumentException("port_id should not be empty");
        }
        VirtualPortId portId = VirtualPortId
                .portId(subnode.get("port_id").asText());
        RouterInterface routerInterface = RouterInterface
                .routerInterface(subnetId, portId, routerId, tenentId);
        get(RouterInterfaceService.class)
                .addRouterInterface(routerInterface);
        return ok(INTFACR_ADD_SUCCESS).build();
    } catch (Exception e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:49,代码来源:RouterWebResource.java

示例12: removeRouterInterface

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@PUT
@Path("{routerUUID}/remove_router_interface")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response removeRouterInterface(@PathParam("routerUUID") String id,
                                      final InputStream input) {
    if (!get(RouterService.class).exists(RouterId.valueOf(id))) {
        return Response.status(NOT_FOUND).entity(NOT_EXIST).build();
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode subnode = mapper.readTree(input);
        if (!subnode.hasNonNull("id")) {
            throw new IllegalArgumentException("id should not be null");
        } else if (subnode.get("id").asText().isEmpty()) {
            throw new IllegalArgumentException("id should not be empty");
        }
        RouterId routerId = RouterId.valueOf(id);
        if (!subnode.hasNonNull("subnet_id")) {
            throw new IllegalArgumentException("subnet_id should not be null");
        } else if (subnode.get("subnet_id").asText().isEmpty()) {
            throw new IllegalArgumentException("subnet_id should not be empty");
        }
        SubnetId subnetId = SubnetId
                .subnetId(subnode.get("subnet_id").asText());
        if (!subnode.hasNonNull("port_id")) {
            throw new IllegalArgumentException("port_id should not be null");
        } else if (subnode.get("port_id").asText().isEmpty()) {
            throw new IllegalArgumentException("port_id should not be empty");
        }
        VirtualPortId portId = VirtualPortId
                .portId(subnode.get("port_id").asText());
        if (!subnode.hasNonNull("tenant_id")) {
            throw new IllegalArgumentException("tenant_id should not be null");
        } else if (subnode.get("tenant_id").asText().isEmpty()) {
            throw new IllegalArgumentException("tenant_id should not be empty");
        }
        TenantId tenentId = TenantId
                .tenantId(subnode.get("tenant_id").asText());
        RouterInterface routerInterface = RouterInterface
                .routerInterface(subnetId, portId, routerId, tenentId);
        get(RouterInterfaceService.class)
                .removeRouterInterface(routerInterface);
        return ok(INTFACR_DEL_SUCCESS).build();
    } catch (Exception e) {
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:49,代码来源:RouterWebResource.java

示例13: changeJsonToSub

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Returns a collection of floatingIps from floatingIpNodes.
 *
 * @param routerNode the router json node
 * @return routers a collection of router
 * @throws Exception when any argument is illegal
 */
public Collection<Router> changeJsonToSub(JsonNode routerNode)
        throws Exception {
    checkNotNull(routerNode, JSON_NOT_NULL);
    Map<RouterId, Router> subMap = new HashMap<RouterId, Router>();
    if (!routerNode.hasNonNull("id")) {
        new IllegalArgumentException("id should not be null");
    } else if (routerNode.get("id").asText().isEmpty()) {
        throw new IllegalArgumentException("id should not be empty");
    }
    RouterId id = RouterId.valueOf(routerNode.get("id").asText());

    if (!routerNode.hasNonNull("tenant_id")) {
        throw new IllegalArgumentException("tenant_id should not be null");
    } else if (routerNode.get("tenant_id").asText().isEmpty()) {
        throw new IllegalArgumentException("tenant_id should not be empty");
    }
    TenantId tenantId = TenantId
            .tenantId(routerNode.get("tenant_id").asText());

    VirtualPortId gwPortId = null;
    if (routerNode.hasNonNull("gw_port_id")) {
        gwPortId = VirtualPortId
                .portId(routerNode.get("gw_port_id").asText());
    }

    if (!routerNode.hasNonNull("status")) {
        throw new IllegalArgumentException("status should not be null");
    } else if (routerNode.get("status").asText().isEmpty()) {
        throw new IllegalArgumentException("status should not be empty");
    }
    Status status = Status.valueOf(routerNode.get("status").asText());

    String routerName = null;
    if (routerNode.hasNonNull("name")) {
        routerName = routerNode.get("name").asText();
    }

    boolean adminStateUp = true;
    checkArgument(routerNode.get("admin_state_up").isBoolean(),
                  "admin_state_up should be boolean");
    if (routerNode.hasNonNull("admin_state_up")) {
        adminStateUp = routerNode.get("admin_state_up").asBoolean();
    }
    boolean distributed = false;
    if (routerNode.hasNonNull("distributed")) {
        distributed = routerNode.get("distributed").asBoolean();
    }
    RouterGateway gateway = null;
    if (routerNode.hasNonNull("external_gateway_info")) {
        gateway = jsonNodeToGateway(routerNode
                .get("external_gateway_info"));
    }
    List<String> routes = new ArrayList<String>();
    DefaultRouter routerObj = new DefaultRouter(id, routerName,
                                                adminStateUp, status,
                                                distributed, gateway,
                                                gwPortId, tenantId, routes);
    subMap.put(id, routerObj);
    return Collections.unmodifiableCollection(subMap.values());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:68,代码来源:RouterWebResource.java

示例14: changeUpdateJsonToSub

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Returns a collection of floatingIps from floatingIpNodes.
 *
 * @param subnode the router json node
 * @param routerId the router identify
 * @return routers a collection of router
 * @throws Exception when any argument is illegal
 */
public Collection<Router> changeUpdateJsonToSub(JsonNode subnode,
                                                String routerId)
                                                        throws Exception {
    checkNotNull(subnode, JSON_NOT_NULL);
    checkNotNull(routerId, "routerId should not be null");
    Map<RouterId, Router> subMap = new HashMap<RouterId, Router>();
    JsonNode routerNode = subnode.get("router");
    RouterId id = RouterId.valueOf(routerId);
    Router sub = nullIsNotFound(get(RouterService.class).getRouter(id),
                                NOT_EXIST);
    TenantId tenantId = sub.tenantId();

    VirtualPortId gwPortId = null;
    if (routerNode.hasNonNull("gw_port_id")) {
        gwPortId = VirtualPortId
                .portId(routerNode.get("gw_port_id").asText());
    }
    Status status = sub.status();

    String routerName = routerNode.get("name").asText();

    checkArgument(routerNode.get("admin_state_up").isBoolean(),
                  "admin_state_up should be boolean");
    boolean adminStateUp = routerNode.get("admin_state_up").asBoolean();

    boolean distributed = sub.distributed();
    if (routerNode.hasNonNull("distributed")) {
        distributed = routerNode.get("distributed").asBoolean();
    }
    RouterGateway gateway = sub.externalGatewayInfo();
    if (routerNode.hasNonNull("external_gateway_info")) {
        gateway = jsonNodeToGateway(routerNode
                .get("external_gateway_info"));
    }
    List<String> routes = new ArrayList<String>();
    DefaultRouter routerObj = new DefaultRouter(id, routerName,
                                                adminStateUp, status,
                                                distributed, gateway,
                                                gwPortId, tenantId, routes);
    subMap.put(id, routerObj);
    return Collections.unmodifiableCollection(subMap.values());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:51,代码来源:RouterWebResource.java

示例15: deserialize

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public AppConfiguration deserialize(JsonParser parser, DeserializationContext ctx) throws IOException {
  AppConfiguration config = new AppConfiguration();
  JsonNode node = parser.getCodec().readTree(parser);

  if (node.hasNonNull("cnfInfo")) {
    final boolean cnfInfo = node.get("cnfInfo").asBoolean();
    config.setCnfInfo(cnfInfo);
  }

  if (node.hasNonNull("tgtInfo")) {
    final boolean tgtInfo = node.get("tgtInfo").asBoolean();
    config.setTgtInfo(tgtInfo);
  }

  if (node.hasNonNull("sysInfo")) {
    final boolean sysInfo = node.get("sysInfo").asBoolean();
    config.setSysInfo(sysInfo);
  }

  if (node.hasNonNull("netInfo")) {
    final boolean netInfo = node.get("netInfo").asBoolean();
    config.setNetInfo(netInfo);
  }

  if (node.hasNonNull("polling")) {
    final Interval polling = Interval.valueOf(node.get("polling").asText());
    config.setPolling(polling);
  }

  if (node.hasNonNull("reconnections")) {
    final Long reconnections = (node.get("reconnections").asLong() >= 0) ?
        node.get("reconnections").asLong()
        :
        Long.MAX_VALUE;
    config.setReconnections(reconnections);
  }

  if (node.hasNonNull("reconnectionWait")) {
    final Interval reconnectionWait = Interval.valueOf(node.get("reconnectionWait").asText());
    config.setReconnectionWait(reconnectionWait);
  }

  if (node.hasNonNull("proxy")) {
    final HttpProxy proxy = HttpProxy.valueOf(node.get("proxy").asText());
    config.setProxy(proxy);
  }

  if (node.hasNonNull("sleep")) {
    final String sleep = node.get("sleep").asText();
    config.setSleep(sleep);
  }

  if (node.hasNonNull("authentication")) {
    Map<String,String> authentication = new HashMap<>();
    node.get("authentication").fields().forEachRemaining(f -> authentication.put(f.getKey(), f.getValue().asText()));
    config.setAuthentication(authentication);
  }

  if (node.hasNonNull("controllers")) {
    List<Controller> controllers = new ArrayList<>();
    Iterator<JsonNode> iter = node.get("controllers").elements();
    while (iter.hasNext()) {
      JsonNode n = iter.next();
      Controller controller = ctx.readValue(n.traverse(parser.getCodec()), Controller.class);
      controllers.add(controller);
    }
    config.setControllers(controllers);
  }

  return config;
}
 
开发者ID:braineering,项目名称:ares,代码行数:73,代码来源:AppConfigurationDeserializer.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.hasNonNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。