Java 类com.fasterxml.jackson.databind.node.NullNode 实例源码

项目:reasonml-idea-plugin    文件:MerlinProcess3.java   
JsonNode execute(String filename, String source, List<String> command) {
    if (!m_found) {
        return NullNode.getInstance();
    }

    String content = "";
    try {
        content = runCommand(filename, source, command);
        JsonNode jsonNode = m_objectMapper.readTree(content);
        JsonNode valueNode = extractResponse(jsonNode);
        return valueNode == null ? NullNode.getInstance() : valueNode;
    } catch (Exception ex) {
        throw new RuntimeException("An error occurred when executing a command for the file " + filename + "\n"
                + "The command is: " + Joiner.join(" ", command) + "\n"
                + "The output from merlin is: " + content, ex);
    }
}
项目:athena    文件:UiExtensionManager.java   
@Activate
public void activate() {
    Serializer serializer = Serializer.using(KryoNamespaces.API,
                    ObjectNode.class, ArrayNode.class,
                    JsonNodeFactory.class, LinkedHashMap.class,
                    TextNode.class, BooleanNode.class,
                    LongNode.class, DoubleNode.class, ShortNode.class,
                    IntNode.class, NullNode.class);

    prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder()
            .withName(ONOS_USER_PREFERENCES)
            .withSerializer(serializer)
            .withRelaxedReadConsistency()
            .build();
    prefsConsistentMap.addListener(prefsListener);
    prefs = prefsConsistentMap.asJavaMap();
    register(core);
    log.info("Started");
}
项目:athena    文件:DistributedNetworkConfigStore.java   
@Activate
public void activate() {
    KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder()
            .register(KryoNamespaces.API)
            .register(ConfigKey.class, ObjectNode.class, ArrayNode.class,
                      JsonNodeFactory.class, LinkedHashMap.class,
                      TextNode.class, BooleanNode.class,
                      LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class,
                      NullNode.class);

    configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder()
            .withSerializer(Serializer.using(kryoBuilder.build()))
            .withName("onos-network-configs")
            .withRelaxedReadConsistency()
            .build();
    configs.addListener(listener);
    log.info("Started");
}
项目:xitikit-blue    文件:VerificationUtil.java   
@Nonnull
public static JsonNode kidForKeyId(
  @Nonnull final JsonNode node,
  @Nonnull final String keyId){

    for(JsonNode keyNode : node){
        if(keyNode
          .get("kid")
          .asText()
          .equals(keyId)){

            return keyNode;
        }
    }
    return NullNode.getInstance();
}
项目:webmate-sdk-java    文件:JobEngine.java   
/**
 * Start existing job and return id of new jobrun
 */
public JobRunId startExistingJob(JobId id) {
    ApiResponse response = this.sendPOST(startJobTemplate, ImmutableMap.of("jobId", id.toString()), NullNode.getInstance());
    Optional<HttpResponse> optHttpResponse = response.getOptHttpResponse();

    if (!optHttpResponse.isPresent()) {
        throw new WebmateApiClientException("Could not start Job with id "+id+". Got no response");
    }

    try {
        String jobRunId = EntityUtils.toString(optHttpResponse.get().getEntity()).replaceAll("\"", "");
        return new JobRunId(UUID.fromString(jobRunId));
    } catch (IOException e) {
        throw new WebmateApiClientException("Could not start Job with id "+id+". Got no JobRunId");
    }
}
项目:hiervis    文件:HVConfig.java   
/**
 * Create a new config from the specified file.
 * 
 * @param file
 *            the file containing config values. Assumed to be in *.json format.
 * @return the loaded confing
 * @throws IOException
 *             if an IO error occurred
 * @throws JsonProcessingException
 *             if an error occurred while processing the json text
 */
public static HVConfig from( File file )
    throws IOException
{
    HVConfig config = new HVConfig();

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure( JsonParser.Feature.ALLOW_COMMENTS, true );
    mapper.configure( JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true );

    JsonNode rootNode = mapper.readTree( file );

    try {
        for ( Field field : HVConfig.class.getDeclaredFields() ) {
            JsonNode node = rootNode.get( field.getName() );
            if ( node != null && node instanceof NullNode == false && isValidField( field ) ) {
                config.setField( field, node );
            }
        }
    }
    catch ( IllegalArgumentException | IllegalAccessException e ) {
        log.error( "Error while processing config fields: ", e );
    }

    return config;
}
项目:vtn    文件:ServiceNetworkCodecTest.java   
/**
 * Checks if decoding service network with null and empty providers allowed.
 */
@Test
public void testServiceNetworkDecodeNullAndEmptyProviders() {
    JsonNode jsonInvalidProvider = context.mapper().createObjectNode()
            .put(ID, ID_1.id())
            .put(NAME, NAME_1)
            .put(TYPE, PRIVATE.name())
            .put(SEGMENT_ID, SEGMENT_ID_1.id())
            .put(SUBNET, SUBNET_1.toString())
            .put(SERVICE_IP, SERVICE_IP_1.toString())
            .set(PROVIDERS, NullNode.getInstance());
    codec.decode((ObjectNode) jsonInvalidProvider, context);

    jsonInvalidProvider = context.mapper().createObjectNode()
            .put(ID, ID_1.id())
            .put(NAME, NAME_1)
            .put(TYPE, PRIVATE.name())
            .put(SEGMENT_ID, SEGMENT_ID_1.id())
            .put(SUBNET, SUBNET_1.toString())
            .put(SERVICE_IP, SERVICE_IP_1.toString())
            .set(PROVIDERS, context.mapper().createArrayNode());
    codec.decode((ObjectNode) jsonInvalidProvider, context);
}
项目:vtn    文件:ServiceNetworkCodecTest.java   
/**
 * Checks if decoding service network with invalid provider fails.
 */
@Test(expected = IllegalArgumentException.class)
public void testServiceNetworkNullProviderId() {
    final ArrayNode jsonProviders = context.mapper().createArrayNode();
    final JsonNode jsonProvider = context.mapper().createObjectNode()
            .put(DEP_TYPE, true)
            .set(ID, NullNode.getInstance());
    jsonProviders.add(jsonProvider);
    final JsonNode jsonInvalidProvider = context.mapper().createObjectNode()
            .put(ID, ID_1.id())
            .put(NAME, NAME_1)
            .put(TYPE, PRIVATE.name())
            .put(SEGMENT_ID, SEGMENT_ID_1.id())
            .put(SUBNET, SUBNET_1.toString())
            .put(SERVICE_IP, SERVICE_IP_1.toString())
            .set(PROVIDERS, jsonProvider);
    codec.decode((ObjectNode) jsonInvalidProvider, context);
}
项目:vtn    文件:ServiceNetworkCodecTest.java   
/**
 * Checks if decoding service network with invalid provider fails.
 */
@Test(expected = IllegalArgumentException.class)
public void testServiceNetworkNullProviderType() {
    final ArrayNode jsonProviders = context.mapper().createArrayNode();
    final JsonNode jsonProvider = context.mapper().createObjectNode()
            .put(ID, PROVIDER_ID_1.id())
            .set(DEP_TYPE, NullNode.getInstance());
    jsonProviders.add(jsonProvider);
    final JsonNode jsonInvalidProvider = context.mapper().createObjectNode()
            .put(ID, ID_1.id())
            .put(NAME, NAME_1)
            .put(TYPE, PRIVATE.name())
            .put(SEGMENT_ID, SEGMENT_ID_1.id())
            .put(SUBNET, SUBNET_1.toString())
            .put(SERVICE_IP, SERVICE_IP_1.toString())
            .set(PROVIDERS, jsonProvider);
    codec.decode((ObjectNode) jsonInvalidProvider, context);
}
项目:vtn    文件:ServicePortCodecTest.java   
/**
 * Checks if null and empty array node is allowed for floating address pairs.
 */
@Test
public void testServicePortDecodeNullAndEmptyAddressPairs() {
    JsonNode jsonInvalidAddrPair = context.mapper().createObjectNode()
            .put(ID, PORT_ID_1.id())
            .put(NETWORK_ID, NETWORK_ID_1.id())
            .put(NAME, PORT_NAME_1)
            .put(IP_ADDRESS, IP_ADDRESS_1.toString())
            .put(MAC_ADDRESS, MAC_ADDRESS_1.toString())
            .put(VLAN_ID, VLAN_ID_1.toShort())
            .set(FLOATING_ADDRESS_PAIRS, NullNode.getInstance());
    codec.decode((ObjectNode) jsonInvalidAddrPair, context);

    jsonInvalidAddrPair = context.mapper().createObjectNode()
            .put(ID, PORT_ID_1.id())
            .put(NETWORK_ID, NETWORK_ID_1.id())
            .put(NAME, PORT_NAME_1)
            .put(IP_ADDRESS, IP_ADDRESS_1.toString())
            .put(MAC_ADDRESS, MAC_ADDRESS_1.toString())
            .put(VLAN_ID, VLAN_ID_1.toShort())
            .set(FLOATING_ADDRESS_PAIRS, context.mapper().createArrayNode());
    codec.decode((ObjectNode) jsonInvalidAddrPair, context);
}
项目:vtn    文件:ServicePortCodecTest.java   
/**
 * Checks if null IP address for floating address pair fails.
 */
@Test(expected = IllegalArgumentException.class)
public void testServicePortDecodeNullFloatingAddrPairIp() {
    final ArrayNode jsonAddrPairs = context.mapper().createArrayNode();
    final JsonNode jsonAddrPair = context.mapper().createObjectNode()
            .put(MAC_ADDRESS, ADDRESS_PAIR_1.mac().toString())
            .set(IP_ADDRESS, NullNode.getInstance());
    jsonAddrPairs.add(jsonAddrPair);
    final JsonNode jsonInvalidAddrPair = context.mapper().createObjectNode()
            .put(ID, PORT_ID_1.id())
            .put(NETWORK_ID, NETWORK_ID_1.id())
            .put(NAME, PORT_NAME_1)
            .put(IP_ADDRESS, IP_ADDRESS_1.toString())
            .put(MAC_ADDRESS, MAC_ADDRESS_1.toString())
            .put(VLAN_ID, VLAN_ID_1.toShort())
            .set(FLOATING_ADDRESS_PAIRS, jsonAddrPairs);
    codec.decode((ObjectNode) jsonInvalidAddrPair, context);
}
项目:vtn    文件:ServicePortCodecTest.java   
/**
 * Checks if null MAC address for floating address pair fails.
 */
@Test(expected = IllegalArgumentException.class)
public void testServicePortDecodeNullFloatingAddrPairMac() {
    final ArrayNode jsonAddrPairs = context.mapper().createArrayNode();
    final JsonNode jsonAddrPair = context.mapper().createObjectNode()
            .put(IP_ADDRESS, ADDRESS_PAIR_1.ip().toString())
            .set(MAC_ADDRESS, NullNode.getInstance());
    jsonAddrPairs.add(jsonAddrPair);
    final JsonNode jsonInvalidAddrPair = context.mapper().createObjectNode()
            .put(ID, PORT_ID_1.id())
            .put(NETWORK_ID, NETWORK_ID_1.id())
            .put(NAME, PORT_NAME_1)
            .put(IP_ADDRESS, IP_ADDRESS_1.toString())
            .put(MAC_ADDRESS, MAC_ADDRESS_1.toString())
            .put(VLAN_ID, VLAN_ID_1.toShort())
            .set(FLOATING_ADDRESS_PAIRS, jsonAddrPairs);
    codec.decode((ObjectNode) jsonInvalidAddrPair, context);
}
项目:haven-platform    文件:ExposedPorts.java   
@Override
public ExposedPorts deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    List<ExposedPort> exposedPorts = new ArrayList<>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext(); ) {

        Map.Entry<String, JsonNode> field = it.next();
        if (!field.getValue().equals(NullNode.getInstance())) {
            exposedPorts.add(ExposedPort.parse(field.getKey()));
        }
    }
    return new ExposedPorts(exposedPorts.toArray(new ExposedPort[0]));
}
项目:haven-platform    文件:Ports.java   
@Override
public Ports deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    Ports out = new Ports();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext(); ) {

        Map.Entry<String, JsonNode> portNode = it.next();
        JsonNode bindingsArray = portNode.getValue();
        if (bindingsArray.equals(NullNode.getInstance())) {
            out.bind(ExposedPort.parse(portNode.getKey()), null);
        } else {
            for (int i = 0; i < bindingsArray.size(); i++) {
                JsonNode bindingNode = bindingsArray.get(i);
                if (!bindingNode.equals(NullNode.getInstance())) {
                    String hostIp = bindingNode.get("HostIp").textValue();
                    String hostPort = bindingNode.get("HostPort").textValue();
                    out.bind(ExposedPort.parse(portNode.getKey()), new Binding(hostIp, hostPort));
                }
            }
        }
    }
    return out;
}
项目:java-stratum    文件:StratumMessageTest.java   
@Test
public void deserialize() throws Exception {
    StratumMessage m1 = readValue("{\"id\":123, \"method\":\"a.b\", \"params\":[1, \"x\", null]}");
    assertEquals(123L, (long)m1.id);
    assertEquals("a.b", m1.method);
    assertEquals(Lists.newArrayList(new IntNode(1), new TextNode("x"), NullNode.getInstance()), m1.params);
    StratumMessage m2 = readValue("{\"id\":123, \"result\":{\"x\": 123}}");
    assertTrue(m2.isResult());
    assertEquals(123L, (long)m2.id);
    assertEquals(mapper.createObjectNode().put("x", 123), m2.result);

    StratumMessage m3 = readValue("{\"id\":123, \"result\":[\"x\"]}");
    assertEquals(123L, (long)m3.id);
    //noinspection AssertEqualsBetweenInconvertibleTypes
    assertEquals(mapper.createArrayNode().add("x"), m3.result);
}
项目:netty-rest    文件:IRequestParameter.java   
public Object extract(ObjectNode node, RakamHttpRequest request)
{
    JsonNode value = node.get(name);
    Object o;
    if (value == null) {
        o = null;
    }
    else {
        try {
            o = mapper.convertValue(value, type);
        }
        catch (IllegalArgumentException e) {
            throw new HttpRequestException(name +
                    " body parameter cannot be cast to " + type.toString() + ": "+e.getMessage(), BAD_REQUEST);
        }
    }

    if (required && (o == null || o == NullNode.getInstance())) {
        throw new HttpRequestException(name + " body parameter is required", BAD_REQUEST);
    }

    return o;
}
项目:webmate-jenkins-plugin    文件:WebmateXBrowserBuilder.java   
synchronized private JobRunSummary trackTestProgress(JobRunId testRunId, PrintStream logger) throws IOException, URISyntaxException {
    Lock l = new ReentrantLock();
    Condition c = l.newCondition();

    l.lock();
    StatusUpdateCheckerTask task = new StatusUpdateCheckerTask(testRunId, getDescriptor().getConnector().jobEngine, logger, l , c);
    Timer timer = new Timer();
    timer.schedule(task, 0, 10000);
    try {
        c.await();
    } catch (InterruptedException e) {
        timer.cancel();
        task.cancel();
        logger.println("Build was aborted. Signaling external test to stop.");
        //TODO actually cancel the testrun
        return new JobRunSummary(JobRunState.FAILED, "JobRun was canceled by user", NullNode.getInstance());
    }
    return task.getStatus();
}
项目:spacedog-server    文件:SettingsResource.java   
@Get("/:id/:field")
@Get("/:id/:field/")
public Payload get(String id, String field) {

    checkIfAuthorizedToRead(id);

    Class<? extends Settings> settingsClass = registeredSettingsClasses.get(id);

    ObjectNode settings = settingsClass == null ? Json8.readObject(load(id)) //
            : Json8.mapper().valueToTree(load(settingsClass));

    JsonNode value = settings.get(field);
    if (value == null)
        value = NullNode.getInstance();

    return JsonPayload.json(value, HttpStatus.OK);
}
项目:spacedog-server    文件:Json8.java   
@Deprecated
public static ValueNode toValueNode(Object value) {

    if (value == null)
        return NullNode.instance;
    if (value instanceof ValueNode)
        return (ValueNode) value;
    if (value instanceof Boolean)
        return BooleanNode.valueOf((boolean) value);
    else if (value instanceof Integer)
        return IntNode.valueOf((int) value);
    else if (value instanceof Long)
        return LongNode.valueOf((long) value);
    else if (value instanceof Double)
        return DoubleNode.valueOf((double) value);
    else if (value instanceof Float)
        return FloatNode.valueOf((float) value);

    return TextNode.valueOf(value.toString());
}
项目:spacedog-server    文件:Json7.java   
public static ValueNode toValueNode(Object value) {

        if (value == null)
            return NullNode.instance;
        if (value instanceof ValueNode)
            return (ValueNode) value;
        if (value instanceof Boolean)
            return BooleanNode.valueOf((boolean) value);
        else if (value instanceof Integer)
            return IntNode.valueOf((int) value);
        else if (value instanceof Long)
            return LongNode.valueOf((long) value);
        else if (value instanceof Double)
            return DoubleNode.valueOf((double) value);
        else if (value instanceof Float)
            return FloatNode.valueOf((float) value);

        return TextNode.valueOf(value.toString());
    }
项目:daikon    文件:JsonSchemaInferrer.java   
/**
 * Get an Avro schema using {@link AvroUtils#wrapAsNullable(Schema)} by node type.
 * 
 * @param node Json node.
 * @return an Avro schema using {@link AvroUtils#wrapAsNullable(Schema)} by node type.
 */
public Schema getAvroSchema(JsonNode node) {
    if (node instanceof TextNode) {
        return AvroUtils.wrapAsNullable(AvroUtils._string());
    } else if (node instanceof IntNode) {
        return AvroUtils.wrapAsNullable(AvroUtils._int());
    } else if (node instanceof LongNode) {
        return AvroUtils.wrapAsNullable(AvroUtils._long());
    } else if (node instanceof DoubleNode) {
        return AvroUtils.wrapAsNullable(AvroUtils._double());
    } else if (node instanceof BooleanNode) {
        return AvroUtils.wrapAsNullable(AvroUtils._boolean());
    } else if (node instanceof NullNode) {
        return AvroUtils.wrapAsNullable(AvroUtils._string());
    } else {
        return Schema.createRecord(getSubRecordRandomName(), null, null, false, getFields(node));
    }
}
项目:ycb-java    文件:LookupTree.java   
public List<ValidationError> validate() {
    final List<PathLeaf> pathLeafs = traverse();

    // find the "Master" delta
    final JsonNode masterDelta = pathLeafs.stream()
            .filter(p -> p.contextValues.stream().allMatch(v -> v.equals(ANY_VALUE)))
            .map(PathLeaf::getDelta)
            .findFirst()
            .orElse(NullNode.getInstance());

    // iterate over all "non-root" deltas
    return pathLeafs.stream()
            .filter(p -> p.contextValues.stream().anyMatch(v -> !v.equals(ANY_VALUE)))
            .flatMap(p -> {
                try {
                    mergeDelta(masterDelta, p.getDelta(), true);
                    return Stream.empty();
                } catch (ValidationException e) {
                    return Stream.of( new ValidationError(e.getPath(), e.getReason(), p.getContextValues()) );
                }
            })
            .collect(Collectors.toList());
}
项目:QuizUpWinner    文件:ObjectReader.java   
protected JsonNode _bindAsTree(JsonParser paramJsonParser)
{
  JsonToken localJsonToken = _initForReading(paramJsonParser);
  Object localObject;
  if ((localJsonToken == JsonToken.VALUE_NULL) || (localJsonToken == JsonToken.END_ARRAY) || (localJsonToken == JsonToken.END_OBJECT))
  {
    localObject = NullNode.instance;
  }
  else
  {
    DefaultDeserializationContext localDefaultDeserializationContext = createDeserializationContext(paramJsonParser, this._config);
    JsonDeserializer localJsonDeserializer = _findRootDeserializer(localDefaultDeserializationContext, JSON_NODE_TYPE);
    if (this._unwrapRoot)
      localObject = (JsonNode)_unwrapAndDeserialize(paramJsonParser, localDefaultDeserializationContext, JSON_NODE_TYPE, localJsonDeserializer);
    else
      localObject = (JsonNode)localJsonDeserializer.deserialize(paramJsonParser, localDefaultDeserializationContext);
  }
  paramJsonParser.clearCurrentToken();
  return localObject;
}
项目:lightblue-mongo    文件:DocTranslator.java   
private void convertArrayFieldToBson(JsonNode node, JsonNodeCursor cursor, BasicDBObject ret, FieldTreeNode fieldMdNode, Path path, EntityMetadata md,ResultMetadata rmd) {
    if (node != null) {
        if (node instanceof ArrayNode) {
            if (cursor.firstChild()) {
                ret.append(path.tail(0), arrayToBson(cursor, ((ArrayField) fieldMdNode).getElement(), md,rmd));
                cursor.parent();
            } else {
                // empty array! add an empty list.
                ret.append(path.tail(0), new ArrayList());
            }
        } else if (node instanceof NullNode) {
            ret.append(path.tail(0), null);
        } else {
            throw Error.get(ERR_INVALID_FIELD, path.toString());
        }
    }
}
项目:lightblue-mongo    文件:DocTranslator.java   
/**
 * @param cursor The cursor, pointing to the first element of the array
 */
@SuppressWarnings({"rawtypes", "unchecked"})
private List arrayToBson(JsonNodeCursor cursor, ArrayElement el, EntityMetadata md,ResultMetadata rmd) {
    List l = new ArrayList();
    if (el instanceof SimpleArrayElement) {
        Type t = el.getType();
        do {
            Object value = toValue(t, cursor.getCurrentNode());
            l.add(value);
        } while (cursor.nextSibling());
    } else {
        do {
            JsonNode node = cursor.getCurrentNode();
            if (node == null || node instanceof NullNode) {
                l.add(null);
            } else if (cursor.firstChild()) {
                l.add(objectToBson(cursor, md,rmd));
                cursor.parent();
            } else {
                l.add(null);
            }
        } while (cursor.nextSibling());
    }
    return l;
}
项目:json-shapeshifter    文件:ArrayConstantBinding.java   
@Override
public Iterator<JsonNode> getValue(JsonNode payload, List<Integer> context) {
    return new Iterator<JsonNode>() {

        private int count = 0;

        @Override
        public boolean hasNext() {
            return count < nbIterations;
        }

        @Override
        public JsonNode next() {
            count++;
            return NullNode.instance;
        }
    };
}
项目:wisdom-wamp    文件:WampControllerRPCTest.java   
@Test
public void testValidInvocationWithNullArg() throws RegistryException {
    message = null;
    Json json = new JsonService();
    WampController controller = createWampControllerAndConnectClient(json);

    Howdy howdy = new Howdy();
    controller.register(howdy, "http://example.com/howdy");

    message = null;
    ArrayNode call = json.newArray();
    call.add(MessageType.CALL.code());
    call.add("7DK6TdN4wLiUJgNM");
    call.add("http://example.com/howdy#complex");
    call.add(NullNode.getInstance());

    controller.onMessage("id", call);

    assertThat(message).isNotNull();
    JsonNode node = json.parse(message);
    assertThat(node.isArray());
    System.out.println(message);
    assertThat(node.get(0).asInt()).isEqualTo(MessageType.CALLRESULT.code());
    assertThat(node.get(1).asText()).isEqualTo("7DK6TdN4wLiUJgNM");
    assertThat(node.get(2).isNull()).isTrue();
}
项目:ineform    文件:JavaPropHandler.java   
@Override
public void setProp(HasProp hasProp, String group, String key, Object value) {
    try {
        ObjectNode groupJSON = getOrCreateJsonGroup(hasProp, group);
        if (value == null) {
            groupJSON.put(key, NullNode.getInstance());
        } else if (value instanceof Long) {
            groupJSON.put(key, LongNode.valueOf((Long) value));
        } else if (value instanceof Double) {
            groupJSON.put(key, DoubleNode.valueOf((Double) value));
        } else if (value instanceof Integer) {
            groupJSON.put(key, IntNode.valueOf((Integer) value));
        } else if (value instanceof Float) {
            groupJSON.put(key, new DoubleNode((double) value));
        } else if (value instanceof String) {
            groupJSON.put(key, TextNode.valueOf((String) value));
        } else if (value instanceof Boolean) {
            groupJSON.put(key, BooleanNode.valueOf((Boolean) value));
        }
        hasProp.setPropsJson(group, groupJSON.toString());
    } catch (Exception e) {
        logSetProp(hasProp, group, key, value);
    }
}
项目:cattle    文件:VolumeBinds.java   
@Override
public VolumeBinds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {

    List<VolumeBind> binds = new ArrayList<>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
        Map.Entry<String, JsonNode> field = it.next();
        JsonNode value = field.getValue();
        if (!value.equals(NullNode.getInstance())) {
            if (!value.isTextual()) {
                throw deserializationContext.mappingException("Expected path for '" + field.getKey() + "'in host but got '" + value + "'.");
            }
            VolumeBind bind = new VolumeBind(value.asText(), field.getKey());
            binds.add(bind);
        }
    }
    return new VolumeBinds(binds.toArray(new VolumeBind[binds.size()]));
}
项目:cattle    文件:Ports.java   
@Override
public Ports deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {

    Ports out = new Ports();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {

        Map.Entry<String, JsonNode> portNode = it.next();
        JsonNode bindingsArray = portNode.getValue();
        for (int i = 0; i < bindingsArray.size(); i++) {
            JsonNode bindingNode = bindingsArray.get(i);
            if (!bindingNode.equals(NullNode.getInstance())) {
                String hostIp = bindingNode.get("HostIp").textValue();
                int hostPort = bindingNode.get("HostPort").asInt();
                out.bind(ExposedPort.parse(portNode.getKey()), new Binding(hostIp, hostPort));
            }
        }
    }
    return out;
}
项目:cattle    文件:Volumes.java   
@Override
public Volumes deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {

    List<Volume> volumes = new ArrayList<>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {

        Map.Entry<String, JsonNode> field = it.next();
        if (!field.getValue().equals(NullNode.getInstance())) {
            Volume volume = Volume.parse(field.getKey());
            volumes.add(volume);
        }
    }
    return new Volumes(volumes.toArray(new Volume[0]));
}
项目:unravl    文件:Json.java   
/**
 * Convert a Java object to a JsonNode
 *
 * @param val
 *            a List, Map, or other object
 * @return a JsonNode that corresponds to the val
 */
@SuppressWarnings("rawtypes")
public static JsonNode wrap(Object val) {
    if (val == null)
        return NullNode.getInstance();
    else if (val instanceof Map)
        return wrap((Map) val);
    else if (val instanceof List)
        return wrap((List) val);
    else {
        ArrayList<Object> o = new ArrayList<Object>(1);
        o.add(val);
        ArrayNode a = wrap(o);
        JsonNode n = a.get(0);
        return n;
    }
}
项目:docker-java    文件:VolumeBinds.java   
@Override
public VolumeBinds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {

    List<VolumeBind> binds = new ArrayList<VolumeBind>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
        Map.Entry<String, JsonNode> field = it.next();
        JsonNode value = field.getValue();
        if (!value.equals(NullNode.getInstance())) {
            if (!value.isTextual()) {
                throw deserializationContext.mappingException("Expected path for '" + field.getKey()
                        + "'in host but got '" + value + "'.");
            }
            VolumeBind bind = new VolumeBind(value.asText(), field.getKey());
            binds.add(bind);
        }
    }
    return new VolumeBinds(binds.toArray(new VolumeBind[binds.size()]));
}
项目:docker-java    文件:VolumesRW.java   
@Override
public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {

    List<VolumeRW> volumesRW = new ArrayList<VolumeRW>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);

    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
        Map.Entry<String, JsonNode> field = it.next();
        JsonNode value = field.getValue();

        if (!value.equals(NullNode.getInstance())) {
            if (!value.isBoolean()) {
                throw deserializationContext.mappingException("Expected access mode for '" + field.getKey()
                        + "' in host but got '" + value + "'.");
            }

            VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean()));
            volumesRW.add(bind);
        }
    }
    return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()]));
}
项目:docker-java    文件:ExposedPorts.java   
@Override
public ExposedPorts deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {

    List<ExposedPort> exposedPorts = new ArrayList<ExposedPort>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {

        Map.Entry<String, JsonNode> field = it.next();
        if (!field.getValue().equals(NullNode.getInstance())) {
            exposedPorts.add(ExposedPort.parse(field.getKey()));
        }
    }
    return new ExposedPorts(exposedPorts.toArray(new ExposedPort[0]));
}
项目:docker-java    文件:Ports.java   
@Override
public Ports deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {

    Ports out = new Ports();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {

        Map.Entry<String, JsonNode> portNode = it.next();
        JsonNode bindingsArray = portNode.getValue();
        if (bindingsArray.equals(NullNode.getInstance())) {
            out.bind(ExposedPort.parse(portNode.getKey()), null);
        } else {
            for (int i = 0; i < bindingsArray.size(); i++) {
                JsonNode bindingNode = bindingsArray.get(i);
                if (!bindingNode.equals(NullNode.getInstance())) {
                    String hostIp = bindingNode.get("HostIp").textValue();
                    String hostPort = bindingNode.get("HostPort").textValue();
                    out.bind(ExposedPort.parse(portNode.getKey()), new Binding(hostIp, hostPort));
                }
            }
        }
    }
    return out;
}
项目:docker-java    文件:Volumes.java   
@Override
public Volumes deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {

    List<Volume> volumes = new ArrayList<Volume>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {

        Map.Entry<String, JsonNode> field = it.next();
        if (!field.getValue().equals(NullNode.getInstance())) {
            String path = field.getKey();
            Volume volume = new Volume(path);
            volumes.add(volume);
        }
    }
    return new Volumes(volumes.toArray(new Volume[0]));
}
项目:onos    文件:DistributedNetworkConfigStore.java   
@Activate
public void activate() {
    KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder()
            .register(KryoNamespaces.API)
            .register(ConfigKey.class, ObjectNode.class, ArrayNode.class,
                      JsonNodeFactory.class, LinkedHashMap.class,
                      TextNode.class, BooleanNode.class,
                      LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class,
                      NullNode.class);

    configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder()
            .withSerializer(Serializer.using(kryoBuilder.build()))
            .withName("onos-network-configs")
            .withRelaxedReadConsistency()
            .build();
    configs.addListener(listener);
    log.info("Started");
}
项目:netty-wamp    文件:AuthReqHandler.java   
@Override
public TreeNode call(final List<TreeNode> args, final HandlerContext ctx) throws CallErrorException {
    if (ctx.getSession().isAuthRequested()) throw new CallErrorException("Already authenticated");

    final String authKey = ((TextNode) args.get(0)).textValue();
    if (!ctx.wampServer.authSecretProvider.keyExists(authKey)) throw new CallErrorException("Authentication key does not exist");

    String extra = null;
    if (args.get(1) != null && !(args.get(1) instanceof NullNode)) {
        extra = ((TextNode) args.get(1)).textValue();
    }

    try {
        final String challenge = HmacSHA256.generate(ctx.getSession().id + System.currentTimeMillis(), authKey);
        ctx.getSession().authKey = authKey;
        ctx.getSession().challenge = challenge;
        return new TextNode(challenge);
    } catch (NoSuchAlgorithmException | InvalidKeyException e) {
        throw new CallErrorException("Internal server error");
    }
}
项目:lightblue-core    文件:MinMaxChecker.java   
@Override
public void checkConstraint(ConstraintValidator validator,
                            FieldTreeNode fieldMetadata,
                            Path fieldMetadataPath,
                            FieldConstraint constraint,
                            Path valuePath,
                            JsonDoc doc,
                            JsonNode fieldValue) {
    Number value = ((MinMaxConstraint) constraint).getValue();
    String type = ((MinMaxConstraint) constraint).getType();
    if (!(fieldValue instanceof NullNode)) {
        int cmp = cmp(fieldValue, value);
        // cmp==0: fieldValue=value
        // cmp <0: fieldValue<value
        // cmp >0: fieldValue>value
        if (MinMaxConstraint.MIN.equals(type)) {
            if (cmp < 0) {
                validator.addDocError(Error.get(CrudConstants.ERR_VALUE_TOO_SMALL, fieldValue.asText()));
            }
        } else if (cmp > 0) {
            validator.addDocError(Error.get(CrudConstants.ERR_VALUE_TOO_LARGE, fieldValue.asText()));
        }
    }
}