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


Java JsonNode.asLong方法代码示例

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


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

示例1: createVirtualDevice

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Creates a virtual device from the JSON input stream.
 *
 * @param networkId network identifier
 * @param stream    virtual device JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel VirtualDevice
 */
@POST
@Path("{networkId}/devices")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVirtualDevice(@PathParam("networkId") long networkId,
                                    InputStream stream) {
    try {
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this);
        JsonNode specifiedNetworkId = jsonTree.get("networkId");
        if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
            throw new IllegalArgumentException(INVALID_FIELD + "networkId");
        }
        final VirtualDevice vdevRes = vnetAdminService.createVirtualDevice(vdevReq.networkId(),
                                                                           vdevReq.id());
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
                .path("vnets").path(specifiedNetworkId.asText())
                .path("devices").path(vdevRes.id().toString());
        return Response
                .created(locationBuilder.build())
                .build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:35,代码来源:VirtualNetworkWebResource.java

示例2: createVirtualLink

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Creates a virtual network link from the JSON input stream.
 *
 * @param networkId network identifier
 * @param stream    virtual link JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel VirtualLink
 */
@POST
@Path("{networkId}/links")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVirtualLink(@PathParam("networkId") long networkId,
                                  InputStream stream) {
    try {
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        JsonNode specifiedNetworkId = jsonTree.get("networkId");
        if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
            throw new IllegalArgumentException(INVALID_FIELD + "networkId");
        }
        final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this);
        vnetAdminService.createVirtualLink(vlinkReq.networkId(),
                                           vlinkReq.src(), vlinkReq.dst());
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
                .path("vnets").path(specifiedNetworkId.asText())
                .path("links");
        return Response
                .created(locationBuilder.build())
                .build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:35,代码来源:VirtualNetworkWebResource.java

示例3: removeVirtualLink

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Removes the virtual network link from the JSON input stream.
 *
 * @param networkId network identifier
 * @param stream    virtual link JSON stream
 * @return 204 NO CONTENT
 * @onos.rsModel VirtualLink
 */
@DELETE
@Path("{networkId}/links")
@Consumes(MediaType.APPLICATION_JSON)
public Response removeVirtualLink(@PathParam("networkId") long networkId,
                                  InputStream stream) {
    try {
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        JsonNode specifiedNetworkId = jsonTree.get("networkId");
        if (specifiedNetworkId != null &&
                specifiedNetworkId.asLong() != (networkId)) {
            throw new IllegalArgumentException(INVALID_FIELD + "networkId");
        }
        final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this);
        vnetAdminService.removeVirtualLink(vlinkReq.networkId(),
                                           vlinkReq.src(), vlinkReq.dst());
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }

    return Response.noContent().build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:30,代码来源:VirtualNetworkWebResource.java

示例4: getJsonValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static Object getJsonValue(JsonNode input, String name, Class type, boolean isRequired, Object defaultValue) throws IllegalArgumentException {
  JsonNode node = input.findPath(name);

  if (node.isMissingNode() || node.isNull()) {
    if (isRequired) {
      throw new IllegalArgumentException(name + " is required!");
    } else {
      return defaultValue;
    }
  }

  if (type.equals(String.class)) {
    return node.textValue();
  }

  if (type.equals(Integer.class)) {
    return node.asInt();
  }

  if (type.equals(Long.class)) {
    return node.asLong();
  }

  if (type.equals(Boolean.class)) {
    return node.asBoolean();
  }

  if (type.equals(Double.class)) {
    return node.asDouble();
  }

  return node.asText();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:34,代码来源:JsonUtil.java

示例5: getDateFromSeconds

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
Date getDateFromSeconds(Map<String, JsonNode> tree, String claimName) {
    JsonNode node = tree.get(claimName);
    if (node == null || node.isNull() || !node.canConvertToLong()) {
        return null;
    }
    final long ms = node.asLong() * 1000;
    return new Date(ms);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:9,代码来源:PayloadDeserializer.java

示例6: getSimpleMemberValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Object getSimpleMemberValue(JsonNode currentNode, MemberModel memberModel) {
    if (memberModel.getHttp().getIsStreaming()) {
        return null;
    }
    switch (memberModel.getVariable().getSimpleType()) {
        case "Long":
            return currentNode.asLong();
        case "Integer":
            return currentNode.asInt();
        case "String":
            return currentNode.asText();
        case "Boolean":
            return currentNode.asBoolean();
        case "Double":
            return currentNode.asDouble();
        case "Instant":
            return Instant.ofEpochMilli(currentNode.asLong());
        case "ByteBuffer":
            return ByteBuffer.wrap(currentNode.asText().getBytes(StandardCharsets.UTF_8));
        case "Float":
            return (float) currentNode.asDouble();
        case "Character":
            return asCharacter(currentNode);
        default:
            throw new IllegalArgumentException(
                    "Unsupported fieldType " + memberModel.getVariable().getSimpleType());
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:29,代码来源:ShapeModelReflector.java

示例7: decode

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Alarm decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }

    log.debug("id={}, full json={} ", json.get("id"), json);
    Long id = json.get("id").asLong();

    DeviceId deviceId = DeviceId.deviceId(json.get("deviceId").asText());
    String description = json.get("description").asText();
    Long timeRaised = json.get("timeRaised").asLong();
    Long timeUpdated = json.get("timeUpdated").asLong();

    JsonNode jsonTimeCleared = json.get("timeCleared");
    Long timeCleared = jsonTimeCleared == null || jsonTimeCleared.isNull() ? null : jsonTimeCleared.asLong();

    Alarm.SeverityLevel severity = Alarm.SeverityLevel.valueOf(json.get("severity").asText().toUpperCase());

    Boolean serviceAffecting = json.get("serviceAffecting").asBoolean();
    Boolean acknowledged = json.get("acknowledged").asBoolean();
    Boolean manuallyClearable = json.get("manuallyClearable").asBoolean();

    JsonNode jsonAssignedUser = json.get("assignedUser");
    String assignedUser
            = jsonAssignedUser == null || jsonAssignedUser.isNull() ? null : jsonAssignedUser.asText();

    return new DefaultAlarm.Builder(
            deviceId, description, severity, timeRaised).forSource(AlarmEntityId.NONE).
            withId(AlarmId.alarmId(id)).
            withTimeUpdated(timeUpdated).
            withTimeCleared(timeCleared).
            withServiceAffecting(serviceAffecting).
            withAcknowledged(acknowledged).
            withManuallyClearable(manuallyClearable).
            withAssignedUser(assignedUser).
            build();

}
 
开发者ID:shlee89,项目名称:athena,代码行数:40,代码来源:AlarmCodec.java

示例8: getNodeData

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public Object getNodeData(Schema schema, JsonNode node) {
    if (node == null || node.isNull()) {
        return null;
    }
    switch (schema.getType()) {
        case INT:
            Preconditions.checkArgument(node.isNumber());
            return node.asInt();
        case LONG:
            Preconditions.checkArgument(node.isNumber());
            return node.asLong();
        case BOOLEAN:
            Preconditions.checkArgument(node.isBoolean());
            return node.asBoolean();
        case DOUBLE:
            Preconditions.checkArgument(node.isNumber());
            return node.asDouble();
        case FLOAT:
            Preconditions.checkArgument(node.isNumber());
            return Double.valueOf(node.asDouble()).floatValue();
        case BYTES:
            Preconditions.checkArgument(node.isTextual());
            String base64 = node.asText();
            return ByteArray.fromBase64(base64);
        case ENUM:
            Preconditions.checkArgument(node.isTextual());
            String enumConst = node.asText();
            EnumSchema es = (EnumSchema) schema;
            return es.getConstant(enumConst);
        case STRING:
            Preconditions.checkArgument(node.isTextual());
            return node.asText();
        case MAP:
            return readMap((MapSchema) schema, node);
        case LIST:
            Preconditions.checkArgument(node.isArray());
            return readList((ListSchema) schema, node);
        case RECORD:
            Preconditions.checkArgument(node.isObject());
            return readRecord((RecordSchema) schema, node);
        case ANY:
            Preconditions.checkArgument(node.isObject());
            return readAny(node);
        default:
            throw new IllegalArgumentException("Unknown schema type " + schema.getType());
    }
}
 
开发者ID:atlascon,项目名称:travny,代码行数:48,代码来源:JsonReader.java

示例9: createVirtualPort

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
     * Creates a virtual network port in a virtual device in a virtual network.
     *
     * @param networkId    network identifier
     * @param virtDeviceId virtual device identifier
     * @param stream       virtual port JSON stream
     * @return status of the request - CREATED if the JSON is correct,
     * BAD_REQUEST if the JSON is invalid
     * @onos.rsModel VirtualPort
     */
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Path("{networkId}/devices/{deviceId}/ports")
    public Response createVirtualPort(@PathParam("networkId") long networkId,
                                      @PathParam("deviceId") String virtDeviceId,
                                      InputStream stream) {
        try {
            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
//            final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this);
            JsonNode specifiedNetworkId = jsonTree.get("networkId");
            JsonNode specifiedDeviceId = jsonTree.get("deviceId");
            if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
                throw new IllegalArgumentException(INVALID_FIELD + "networkId");
            }
            if (specifiedDeviceId == null || !specifiedDeviceId.asText().equals(virtDeviceId)) {
                throw new IllegalArgumentException(INVALID_FIELD + "deviceId");
            }
            JsonNode specifiedPortNum = jsonTree.get("portNum");
            JsonNode specifiedPhysDeviceId = jsonTree.get("physDeviceId");
            JsonNode specifiedPhysPortNum = jsonTree.get("physPortNum");
            final NetworkId nid = NetworkId.networkId(networkId);
            DeviceId vdevId = DeviceId.deviceId(virtDeviceId);
            DefaultAnnotations annotations = DefaultAnnotations.builder().build();
            Device physDevice = new DefaultDevice(null, DeviceId.deviceId(specifiedPhysDeviceId.asText()),
                                                  null, null, null, null, null, null, annotations);
            Port realizedBy = new DefaultPort(physDevice,
                                              PortNumber.portNumber(specifiedPhysPortNum.asText()), true);
            VirtualPort vport = vnetAdminService.createVirtualPort(nid, vdevId,
                                    PortNumber.portNumber(specifiedPortNum.asText()), realizedBy);
            UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
                    .path("vnets").path(specifiedNetworkId.asText())
                    .path("devices").path(specifiedDeviceId.asText())
                    .path("ports").path(vport.number().toString());
            return Response
                    .created(locationBuilder.build())
                    .build();
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
    }
 
开发者ID:shlee89,项目名称:athena,代码行数:52,代码来源:VirtualNetworkWebResource.java

示例10: matchesSafely

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Matches the contents of a meter band.
 *
 * @param bandJson JSON representation of band to match
 * @param description Description object used for recording errors
 * @return true if contents match, false otherwise
 */
@Override
protected boolean matchesSafely(JsonNode bandJson, Description description) {
    // check type
    final String jsonType = bandJson.get("type").textValue();
    if (!band.type().name().equals(jsonType)) {
        description.appendText("type was " + jsonType);
        return false;
    }

    // check rate
    final long jsonRate = bandJson.get("rate").longValue();
    if (band.rate() != jsonRate) {
        description.appendText("rate was " + jsonRate);
        return false;
    }

    // check burst size
    final long jsonBurstSize = bandJson.get("burstSize").longValue();
    if (band.burst() != jsonBurstSize) {
        description.appendText("burst size was " + jsonBurstSize);
        return false;
    }

    // check precedence
    final JsonNode jsonNodePrec = bandJson.get("prec");
    if (jsonNodePrec != null) {
        if (band.dropPrecedence() != jsonNodePrec.shortValue()) {
            description.appendText("drop precedence was " + jsonNodePrec.shortValue());
            return false;
        }
    }

    // check packets
    final JsonNode jsonNodePackets = bandJson.get("packets");
    if (jsonNodePackets != null) {
        if (band.packets() != jsonNodePackets.asLong()) {
            description.appendText("packets was " + jsonNodePackets.asLong());
            return false;
        }
    }

    final JsonNode jsonNodeBytes = bandJson.get("bytes");
    if (jsonNodeBytes != null) {
        if (band.bytes() != jsonNodeBytes.asLong()) {
            description.appendText("bytes was " + jsonNodeBytes.asLong());
            return false;
        }
    }

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


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