Java 类javax.json.JsonValue.ValueType 实例源码

项目:virtual-schemas    文件:RequestJsonParser.java   
private static String readAdapterNotes(JsonObject root) {
    if (root.containsKey("adapterNotes")) {
        JsonValue notes = root.get("adapterNotes");
        if (notes.getValueType() == ValueType.STRING) {
            // Return unquoted string
            return ((JsonString)notes).getString();
        } else {
            return notes.toString();
        }
    }
    return "";
}
项目:step    文件:CallFunctionHandler.java   
private Map<String, String> jsonToMap(JsonObject jsonOutput) {
    Map<String, String> resultMap = new HashMap<>();
    for(String key:jsonOutput.keySet()) {
        JsonValue value = jsonOutput.get(key);
        if(value.getValueType() == ValueType.STRING) {
            resultMap.put(key, jsonOutput.getString(key));
        } else if (!value.getValueType().equals(ValueType.OBJECT)&&!value.getValueType().equals(ValueType.ARRAY)) {
            resultMap.put(key, jsonOutput.getString(key).toString());
        }
    }
    return resultMap;
}
项目:cookjson    文件:NumberTest.java   
@Test
public void testInt ()
{
    JsonNumber v = new CookJsonInt (1234);

    Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

    Assert.assertEquals (true, v.isIntegral ());
    Assert.assertEquals (1234, v.intValue ());
    Assert.assertEquals (1234, v.intValueExact ());
    Assert.assertEquals (1234, v.longValue ());
    Assert.assertEquals (1234, v.longValueExact ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValue ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValueExact ());
    Assert.assertEquals (new BigDecimal (1234), v.bigDecimalValue ());
    Assert.assertEquals (1234, v.doubleValue (), 0);
    Assert.assertEquals (new BigDecimal (1234).hashCode (), v.hashCode ());
    Assert.assertEquals ("1234", v.toString ());
}
项目:cookjson    文件:NumberTest.java   
@Test
public void testLong ()
{
    long d = 1234;
    JsonNumber v = new CookJsonLong (d);

    Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

    Assert.assertEquals (true, v.isIntegral ());
    Assert.assertEquals (1234, v.intValue ());
    Assert.assertEquals (1234, v.intValueExact ());
    Assert.assertEquals (d, v.longValue ());
    Assert.assertEquals (d, v.longValueExact ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValue ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValueExact ());
    Assert.assertEquals (new BigDecimal (d), v.bigDecimalValue ());
    Assert.assertEquals (d, v.doubleValue (), 0);
    Assert.assertEquals (new BigDecimal (d).hashCode (), v.hashCode ());
    Assert.assertEquals ("1234", v.toString ());
}
项目:cookjson    文件:NumberTest.java   
@Test
public void testDouble ()
{
    double d = 1234;
    JsonNumber v = new CookJsonDouble (d);

    Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

    Assert.assertEquals (false, v.isIntegral ());
    Assert.assertEquals (1234, v.intValue ());
    Assert.assertEquals (1234, v.intValueExact ());
    Assert.assertEquals (1234, v.longValue ());
    Assert.assertEquals (1234, v.longValueExact ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValue ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValueExact ());
    Assert.assertEquals (BigDecimal.valueOf (d), v.bigDecimalValue ());
    Assert.assertEquals (d, v.doubleValue (), 0);
    Assert.assertEquals (BigDecimal.valueOf (d).hashCode (), v.hashCode ());
    Assert.assertEquals (DoubleUtils.toString (d), v.toString ());
}
项目:cookjson    文件:NumberTest.java   
@Test
public void testBigInteger ()
{
    BigInteger d = new BigInteger ("1234");
    JsonNumber v = new CookJsonBigDecimal (d);

    Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

    Assert.assertEquals (true, v.isIntegral ());
    Assert.assertEquals (d.intValue (), v.intValue ());
    Assert.assertEquals (d.intValue (), v.intValueExact ());
    Assert.assertEquals (d.longValue (), v.longValue ());
    Assert.assertEquals (d.longValue (), v.longValueExact ());
    Assert.assertEquals (d, v.bigIntegerValue ());
    Assert.assertEquals (d, v.bigIntegerValueExact ());
    Assert.assertEquals (new BigDecimal (d), v.bigDecimalValue ());
    Assert.assertEquals (d.doubleValue (), v.doubleValue (), 0);
    Assert.assertEquals (new BigDecimal (d).hashCode (), v.hashCode ());
    Assert.assertEquals (d.toString (), v.toString ());
}
项目:cookjson    文件:NumberTest.java   
@Test
    public void testBigDecimal ()
    {
        BigDecimal d = new BigDecimal ("1234.1234");
        JsonNumber v = new CookJsonBigDecimal (d);

        Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

        Assert.assertEquals (false, v.isIntegral ());
        Assert.assertEquals (d.intValue (), v.intValue ());
//      Assert.assertEquals (d.intValue (), v.intValueExact ());
        Assert.assertEquals (d.longValue (), v.longValue ());
//      Assert.assertEquals (d.longValue (), v.longValueExact ());
        Assert.assertEquals (d.toBigInteger (), v.bigIntegerValue ());
//      Assert.assertEquals (d.toBigInteger (), v.bigIntegerValueExact ());
        Assert.assertEquals (d, v.bigDecimalValue ());
        Assert.assertEquals (d.doubleValue (), v.doubleValue (), 0);
        Assert.assertEquals (d.hashCode (), v.hashCode ());
        Assert.assertEquals (d.toString (), v.toString ());
    }
项目:cookjson    文件:CookJsonBinaryTest.java   
@Test
public void test ()
{
    byte[] bytes = "test".getBytes (BOM.utf8);
    CookJsonBinary v = new CookJsonBinary (bytes.clone ());
    Assert.assertEquals (Arrays.hashCode (bytes), v.hashCode ());
    Assert.assertEquals (ValueType.STRING, v.getValueType ());
    Assert.assertArrayEquals (bytes, v.getBytes ());

    String base64 = Base64.encodeBase64String (bytes);
    Assert.assertEquals (base64, v.getString ());
    Assert.assertEquals (base64, v.getChars ());
    Assert.assertEquals ('"' + base64 + '"', v.toString ());
    Assert.assertEquals (BinaryFormat.BINARY_FORMAT_BASE64, v.getBinaryFormat ());

    v.setBinaryFormat (BinaryFormat.BINARY_FORMAT_HEX);
    String hex = Hex.encodeHexString (bytes);
    Assert.assertEquals (hex, v.getString ());
    Assert.assertEquals (hex, v.getChars ());
    Assert.assertEquals ('"' + hex + '"', v.toString ());
    Assert.assertEquals (BinaryFormat.BINARY_FORMAT_HEX, v.getBinaryFormat ());
}
项目:jkool-client-java-api    文件:JKUtils.java   
public static JsonValue getJsonValue(String json_path, JsonObject response) {
    StringTokenizer tk = new StringTokenizer(json_path, "/");

    JsonValue rValue = response;
    JsonObject value = response;
    while (tk.hasMoreTokens()) {
        String key = tk.nextToken();
        rValue = value.get(key);
        if (rValue == null || (rValue.getValueType() != ValueType.OBJECT)) {
            break;
        } else {
            value = (JsonObject) rValue;
        }
    }
    return rValue;
}
项目:tool.lars    文件:SingleFileClient.java   
/**
 * Return a map from id to JsonObject representing an Asset
 * <p>
 * This method will re-read the json file if it has not yet been read, or if it has changed since we last read it.
 */
private synchronized Map<String, JsonObject> getAssetMap() throws IOException {
    if (!file.canRead()) {
        throw new IOException("Cannot read repository file: " + file.getAbsolutePath());
    } else if (assets == null || file.lastModified() != fileLastModified || file.length() != fileLastSize) {
        // Re-read the file if either we've never read it or it's changed length since we last read it
        assets = null;
        fileLastModified = file.lastModified();
        fileLastSize = file.length();

        idCounter = new AtomicInteger(1);
        assets = new HashMap<String, JsonObject>();
        JsonReader reader = Json.createReader(new FileInputStream(file));
        JsonArray assetList = reader.readArray();
        for (JsonValue val : assetList) {
            String id = Integer.toString(idCounter.getAndIncrement());
            if (val.getValueType() == ValueType.OBJECT) {
                assets.put(id, (JsonObject) val);
            }
        }
    }

    return assets;
}
项目:gameon-mediator    文件:RoutedMessage.java   
/**
 * Get optional long value out of the message json payload
 *
 * @param key
 *            Key to find value for
 * @return value in object or null
 */
public String getString(String key) {
    String result = null;
    JsonObject obj = getParsedBody();
    JsonValue value = obj.get(key);
    if ( value != null ) {
        try {
            if ( value.getValueType() == ValueType.STRING) {
                result = obj.getString(key);
            } else {
                result = value.toString();
            }
        } catch (Exception e) { // class cast, etc
            Log.log(Level.FINER, this, "Exception parsing String: " + value, e);
            // fall through to return default value
        }
    }

    return result;
}
项目:gameon-mediator    文件:RoutedMessage.java   
/**
 * @param key
 * @return JsonArray value or null
 */
public List<Long> getLongArray(String key, List<Long> defaultValue) {
    JsonObject obj = getParsedBody();
    JsonValue arrayValue = obj.get(key);
    if ( arrayValue != null && arrayValue.getValueType() == ValueType.ARRAY ) {
        try {
            List<Long> result = new ArrayList<>();
            ((JsonArray) arrayValue).forEach(value -> result.add(((JsonNumber) value).longValue()));
            return result;
        } catch (Exception e) { // class cast, etc
            Log.log(Level.FINER, this, "Exception parsing JsonArray: " + arrayValue, e);
            // fall through to return default value
        }
    }
    return defaultValue;
}
项目:FHIR-Server    文件:JsonParser.java   
@Override
public TagList parseTagList(Reader theReader) {
    JsonReader reader = Json.createReader(theReader);
    JsonObject object = reader.readObject();

    JsonValue resourceTypeObj = object.get("resourceType");
    assertObjectOfType(resourceTypeObj, JsonValue.ValueType.STRING, "resourceType");
    String resourceType = ((JsonString) resourceTypeObj).getString();

    ParserState<TagList> state = ParserState.getPreTagListInstance(myContext, true);
    state.enteringNewElement(null, resourceType);

    parseChildren(object, state);

    state.endingElement();

    return state.getObject();
}
项目:johnzon    文件:JsonInMemoryParser.java   
private static Event getEvent(final ValueType value) {

        switch (value) {
        case NUMBER:
            return Event.VALUE_NUMBER;
        case STRING:
            return Event.VALUE_STRING;
        case FALSE:
            return Event.VALUE_FALSE;
        case NULL:
            return Event.VALUE_NULL;
        case TRUE:
            return Event.VALUE_TRUE;
        default:
            throw new IllegalArgumentException(value + " not supported");

        }

    }
项目:btc4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcAddedNode jsonAddedNode(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcAddedNode addedNode = new BtcAddedNode();
    addedNode.setAddedNode(object.getString(BTCOBJ_NODE_ADDED_NODE, ""));
    addedNode.setConnected(object.getBoolean(BTCOBJ_NODE_CONNECTED,
            false));
    List<BtcNode> nodes = new ArrayList<BtcNode>();
    JsonValue addresses = object.get(BTCOBJ_NODE_ADDRESSES);
    if ((addresses != null) && (addresses.getValueType() == JsonValue.ValueType.ARRAY) && (addresses instanceof JsonArray)) {
        JsonArray addressesArray = (JsonArray) addresses;
        for (JsonValue address : addressesArray
                .getValuesAs(JsonValue.class)) {
            nodes.add(jsonNode(address));
        }
    }
    addedNode.setAddresses(nodes);
    return addedNode;
}
项目:btc4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcCoinbase jsonCoinbase(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcCoinbase coin = new BtcCoinbase();
    Map<String, String> auxiliary = new HashMap<String, String>();
    JsonValue aux = object.get(BTCOBJ_COIN_AUX);
    if ((aux != null) && (aux.getValueType() == JsonValue.ValueType.OBJECT) && (aux instanceof JsonObject)) {
        JsonObject auxObject = (JsonObject) aux;
        for (String key : auxObject.keySet()) {
            auxiliary.put(key, auxObject.getString(key, ""));
        }
    }
    coin.setAux(auxiliary);
    coin.setValue(jsonDouble(object, BTCOBJ_COIN_VALUE));
    return coin;
}
项目:btc4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcLastBlock jsonLastBlock(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcLastBlock lastBlock = new BtcLastBlock();
    lastBlock.setLastBlock(object.getString(
            BTCOBJ_LAST_BLOCK_LAST_BLOCK, ""));
    List<BtcTransaction> transactions = new ArrayList<BtcTransaction>();
    JsonValue txs = object.get(BTCOBJ_LAST_BLOCK_TRANSACTIONS);
    if ((txs != null) && (txs.getValueType() == JsonValue.ValueType.ARRAY) && (txs instanceof JsonArray)) {
        JsonArray txsArray = (JsonArray) txs;
        for (JsonValue tx : txsArray.getValuesAs(JsonValue.class)) {
            transactions.add(jsonTransaction(tx));
        }
    }
    lastBlock.setTransactions(transactions);
    return lastBlock;
}
项目:btc4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcScript jsonScript(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcScript script = new BtcScript();
    script.setAsm(object.getString(BTCOBJ_SCRIPT_ASM, ""));
    script.setPublicKey(object.getString(BTCOBJ_SCRIPT_PUBLIC_KEY, ""));
    script.setRequiredSignatures(jsonLong(object,
            BTCOBJ_SCRIPT_REQUIRED_SIGNATURES));
    script.setType(BtcScript.Type.getValue(object.getString(
            BTCOBJ_SCRIPT_TYPE, "")));
    List<String> addresses = new ArrayList<String>();
    JsonValue addrs = object.get(BTCOBJ_SCRIPT_ADDRESSES);
    if ((addrs) != null && (addrs.getValueType() == JsonValue.ValueType.ARRAY) && (addrs instanceof JsonArray)) {
        JsonArray addrsArray = (JsonArray) addrs;
        for (JsonValue addr : addrsArray.getValuesAs(JsonValue.class)) {
            addresses.add(jsonString(addr));
        }
    }
    script.setAddresses(addresses);
    return script;
}
项目:btc4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcInput jsonInput(JsonValue value)
        throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcInput input = new BtcInput();
    input.setTransaction(object.getString(BTCOBJ_TX_INPUT_TRANSACTION,
            ""));
    input.setOutput(jsonLong(object, BTCOBJ_TX_INPUT_OUTPUT));
    JsonValue script = object
            .get(BTCOBJ_TX_INPUT_SCRIPT_SIGNATURE);
    if ((script != null) && (script.getValueType() == JsonValue.ValueType.OBJECT) && (script instanceof JsonObject)) {
        input.setScript(jsonScript(script));
    }
    input.setSequence(jsonLong(object, BTCOBJ_TX_INPUT_SEQUENCE));
    return input;
}
项目:noo4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcAddedNode jsonAddedNode(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcAddedNode addedNode = new BtcAddedNode();
    addedNode.setAddedNode(object.getString(BTCOBJ_NODE_ADDED_NODE, ""));
    addedNode.setConnected(object.getBoolean(BTCOBJ_NODE_CONNECTED,
            false));
    List<BtcNode> nodes = new ArrayList<BtcNode>();
    JsonValue addresses = object.get(BTCOBJ_NODE_ADDRESSES);
    if ((addresses != null) && (addresses.getValueType() == JsonValue.ValueType.ARRAY) && (addresses instanceof JsonArray)) {
        JsonArray addressesArray = (JsonArray) addresses;
        for (JsonValue address : addressesArray
                .getValuesAs(JsonValue.class)) {
            nodes.add(jsonNode(address));
        }
    }
    addedNode.setAddresses(nodes);
    return addedNode;
}
项目:noo4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcCoinbase jsonCoinbase(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcCoinbase coin = new BtcCoinbase();
    Map<String, String> auxiliary = new HashMap<String, String>();
    JsonValue aux = object.get(BTCOBJ_COIN_AUX);
    if ((aux != null) && (aux.getValueType() == JsonValue.ValueType.OBJECT) && (aux instanceof JsonObject)) {
        JsonObject auxObject = (JsonObject) aux;
        for (String key : auxObject.keySet()) {
            auxiliary.put(key, auxObject.getString(key, ""));
        }
    }
    coin.setAux(auxiliary);
    coin.setValue(jsonDouble(object, BTCOBJ_COIN_VALUE));
    return coin;
}
项目:noo4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcLastBlock jsonLastBlock(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcLastBlock lastBlock = new BtcLastBlock();
    lastBlock.setLastBlock(object.getString(
            BTCOBJ_LAST_BLOCK_LAST_BLOCK, ""));
    List<BtcTransaction> transactions = new ArrayList<BtcTransaction>();
    JsonValue txs = object.get(BTCOBJ_LAST_BLOCK_TRANSACTIONS);
    if ((txs != null) && (txs.getValueType() == JsonValue.ValueType.ARRAY) && (txs instanceof JsonArray)) {
        JsonArray txsArray = (JsonArray) txs;
        for (JsonValue tx : txsArray.getValuesAs(JsonValue.class)) {
            transactions.add(jsonTransaction(tx));
        }
    }
    lastBlock.setTransactions(transactions);
    return lastBlock;
}
项目:noo4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcScript jsonScript(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcScript script = new BtcScript();
    script.setAsm(object.getString(BTCOBJ_SCRIPT_ASM, ""));
    script.setPublicKey(object.getString(BTCOBJ_SCRIPT_PUBLIC_KEY, ""));
    script.setRequiredSignatures(jsonLong(object,
            BTCOBJ_SCRIPT_REQUIRED_SIGNATURES));
    script.setType(BtcScript.Type.getValue(object.getString(
            BTCOBJ_SCRIPT_TYPE, "")));
    List<String> addresses = new ArrayList<String>();
    JsonValue addrs = object.get(BTCOBJ_SCRIPT_ADDRESSES);
    if ((addrs) != null && (addrs.getValueType() == JsonValue.ValueType.ARRAY) && (addrs instanceof JsonArray)) {
        JsonArray addrsArray = (JsonArray) addrs;
        for (JsonValue addr : addrsArray.getValuesAs(JsonValue.class)) {
            addresses.add(jsonString(addr));
        }
    }
    script.setAddresses(addresses);
    return script;
}
项目:noo4j-daemon    文件:BtcJsonRpcHttpClient.java   
public BtcInput jsonInput(JsonValue value)
        throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }
    BtcInput input = new BtcInput();
    input.setTransaction(object.getString(BTCOBJ_TX_INPUT_TRANSACTION,
            ""));
    input.setOutput(jsonLong(object, BTCOBJ_TX_INPUT_OUTPUT));
    JsonValue script = object
            .get(BTCOBJ_TX_INPUT_SCRIPT_SIGNATURE);
    if ((script != null) && (script.getValueType() == JsonValue.ValueType.OBJECT) && (script instanceof JsonObject)) {
        input.setScript(jsonScript(script));
    }
    input.setSequence(jsonLong(object, BTCOBJ_TX_INPUT_SEQUENCE));
    return input;
}
项目:Megapode    文件:FormParser.java   
public List<NameValuePair> parse(byte[] data){
            List<NameValuePair> formElements = new ArrayList<NameValuePair>();
            JsonReader reader = Json.createReader(new StringReader(new String(data)));
            JsonObject object = reader.readObject();
            for (String key: object.keySet()){
                //JsonValue value = object.get(key);
                if (object.get(key).getValueType() == ValueType.ARRAY){
                    JsonArray values = object.getJsonArray(key);
                    for (int i = 0; i < values.size(); i++){
                        formElements.add(new BasicNameValuePair(key, values.getString(i)));
                    }
//                  value
                } else {
                    formElements.add(new BasicNameValuePair(key, object.getString(key)));
                }
            }
            return formElements;
//          return URLEncodedUtils.parse(new String(data), Charset.forName("UTF-8"));
        }
项目:JsonDBObject    文件:TestParserHelper.java   
@Test
public void testWithPrimitives() {
    JsonValue json1 = ParserHelper.parseToJsonValue(true);
    assertEquals(ValueType.TRUE, json1.getValueType());

    JsonValue json2 = ParserHelper.parseToJsonValue(false);
    assertEquals(ValueType.FALSE, json2.getValueType());

    JsonValue json3 = ParserHelper.parseToJsonValue("test");
    assertEquals(ValueType.STRING, json3.getValueType());
    JsonString string = (JsonString)json3;
    assertEquals("test", string.getString());

    JsonValue json4 = ParserHelper.parseToJsonValue(12345);
    assertEquals(ValueType.NUMBER, json4.getValueType());
    JsonNumber number = (JsonNumber)json4;
    assertEquals(12345, number.intValue());
}
项目:JsonDBObject    文件:TestParserHelper.java   
@Test
public void testWithSimpleObject() {
    SimpleObject simple = ObjectGenerator.createSimpleObject();
    simple.setTitle(null);

    JsonValue json = ParserHelper.parseToJsonValue(simple);
    assertNotNull(json);
    assertEquals(ValueType.OBJECT, json.getValueType());

    JsonDBObject jsonDBObject = (JsonDBObject)json;
    assertEquals("test",    jsonDBObject.getString("name"));
    assertEquals(1,         jsonDBObject.getInt("id"));
    assertEquals(123,       jsonDBObject.getInt("number"));

    assertEquals("{\"id\":1,\"name\":\"test\",\"number\":123,\"title\":null,\"value\":true}", jsonDBObject.toString());
}
项目:JsonDBObject    文件:TestParserHelper.java   
@Test
public void testWithComplexObject() {
    ComplexObject complex = ObjectGenerator.createComplexObject();

    JsonValue json = ParserHelper.parseToJsonValue(complex);
    assertNotNull(json);
    assertEquals(ValueType.OBJECT, json.getValueType());

    JsonDBObject jsonDBObject       = (JsonDBObject)json;

    assertEquals("{\"id\":2,"
            + "\"name\":\"complex\","
            + "\"simple\":{\"id\":1,"
                        + "\"number\":123,"
                        + "\"name\":\"test\","
                        + "\"title\":\"TestTitle\","
                        + "\"value\":true}}", jsonDBObject.toString());
}
项目:JsonDBObject    文件:TestParserHelper.java   
@Test
public void testWithListObject() {
    ListObject object = ObjectGenerator.createListObject();

    JsonValue json = ParserHelper.parseToJsonValue(object);
    assertEquals(ValueType.OBJECT, json.getValueType());

    JsonDBObject jsonDBObject       = (JsonDBObject)json;

    assertEquals("{\"id\":100,"
                + "\"list\":[{\"id\":1,"
                           + "\"number\":123,"
                           + "\"name\":\"test\","
                           + "\"title\":\"TestTitle\","
                           + "\"value\":true},"
                          + "{\"id\":2,"
                           + "\"number\":123,"
                           + "\"name\":\"second test\","
                           + "\"title\":\"TestTitle\","
                           + "\"value\":true}],"
                + "\"name\":\"testListObject\"}", jsonDBObject.toString());
}
项目:JsonDBObject    文件:TestParserHelper.java   
@Test
public void testWithMapObject() {
    MapObject map = ObjectGenerator.createMapObject();

    JsonValue json = ParserHelper.parseToJsonValue(map);
    assertEquals(ValueType.OBJECT, json.getValueType());

    JsonDBObject jsonDBObject       = (JsonDBObject)json;

    assertEquals("{\"id\":100,"
                + "\"map\":{\"key2\":{\"id\":2,"
                                   + "\"number\":123,"
                                   + "\"name\":\"second test\","
                                   + "\"title\":\"TestTitle\","
                                   + "\"value\":true},"
                        +  "\"key1\":{\"id\":1,"
                                   + "\"number\":123,"
                                   + "\"name\":\"test\","
                                   + "\"title\":\"TestTitle\","
                                   + "\"value\":true}},"
                        +  "\"name\":\"testMapObject\"}", jsonDBObject.toString());
}
项目:devtools-driver    文件:WebInspectorHelper.java   
private ImmutableList<CallArgument> processScriptArguments(JsonArray args) {
  ImmutableList.Builder<CallArgument> argsBuilder = ImmutableList.builder();
  for (JsonValue arg : args) {
    if (ValueType.OBJECT.equals(arg.getValueType())) {
      JsonObject jsonArg = (JsonObject) arg;
      if (jsonArg.containsKey("ELEMENT")) {
        NodeId n = new NodeId(Integer.parseInt(jsonArg.getString("ELEMENT").split("_")[1]));
        RemoteWebElement rwep = new RemoteWebElement(n, this);
        argsBuilder.add(callArgument().withObjectId(rwep.getRemoteObject().getId()));
      } else {
        log.info("JsonObject without ELEMENT tag" + jsonArg);
      }
    } else if (ValueType.ARRAY.equals(arg.getValueType())) {
      JsonObject array = getScriptResponse("return " + arg + ";");
      argsBuilder.add(callArgument().withObjectId(getResponseBody(array).getString("objectId")));
    } else if (ValueType.FALSE.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(false));
    } else if (ValueType.TRUE.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(true));
    } else if (ValueType.NUMBER.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(((JsonNumber) arg).longValue()));
    } else if (ValueType.STRING.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(((JsonString) arg).getString()));
    } else {
      throw new WebDriverException("Unsupported argument type: " + arg.getValueType());
    }
  }
  return argsBuilder.build();
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:JsonUtil.java   
@SuppressWarnings("unchecked")
public static <T> T unbox(JsonValue value) {
    return (T) unbox(value, json -> json.getValueType() == ValueType.ARRAY ? 
            ((JsonArray) json).stream()
                .map(JsonUtil::unbox)
                .collect(Collectors.toList())
            :
            ((JsonObject) json).entrySet().stream()
                .map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(),unbox(entry.getValue())))
                .collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
}
项目:Peking-University-Open-Research-Data-Platform    文件:Dataverses.java   
@POST
@Path("{identifier}/metadatablocks")
@Produces(MediaType.APPLICATION_JSON)
public Response setMetadataBlocks( @PathParam("identifier")String dvIdtf, @QueryParam("key") String apiKey, String blockIds ) {

    List<MetadataBlock> blocks = new LinkedList<>();
    try {
        for ( JsonValue blockId : Util.asJsonArray(blockIds).getValuesAs(JsonValue.class) ) {
            MetadataBlock blk = (blockId.getValueType()==ValueType.NUMBER)
                                    ? findMetadataBlock( ((JsonNumber)blockId).longValue() )
                                    : findMetadataBlock( ((JsonString)blockId).getString() );
            if ( blk == null ) {
                return errorResponse(Response.Status.BAD_REQUEST, "Can't find metadata block '"+ blockId + "'");
            }
            blocks.add( blk );
        }
    } catch( Exception e ) {
        return errorResponse(Response.Status.BAD_REQUEST, e.getMessage());
    }

    try {
        User u = findUserOrDie(apiKey);
        Dataverse dataverse = findDataverseOrDie(dvIdtf);
        execCommand( new UpdateDataverseMetadataBlocksCommand.SetBlocks(u, dataverse, blocks),
                "updating metadata blocks for dataverse " + dvIdtf );
        return okResponse("Metadata blocks of dataverse " + dvIdtf + " updated.");

    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
项目:fabric-sdk-java    文件:NetworkConfig.java   
private static Boolean getJsonValueAsBoolean(JsonValue value) {
    if (value != null) {
        if (value.getValueType() == ValueType.TRUE) {
            return true;
        } else if (value.getValueType() == ValueType.FALSE) {
            return false;
        }
    }
    return null;
}
项目:fabric-sdk-java    文件:NetworkConfig.java   
private static JsonObject getJsonObject(JsonObject object, String propName) {
    JsonObject obj = null;
    JsonValue val = object.get(propName);
    if (val != null && val.getValueType() == ValueType.OBJECT) {
        obj = val.asJsonObject();
    }
    return obj;
}
项目:real1ty    文件:Application.java   
private static String getValue(JsonValue value) {
    if (value.getValueType().equals(ValueType.STRING)) {
        JsonString s = (JsonString) value;
        return s.getString();
    } else {
        return value.toString();
    }
}
项目:cookjson    文件:CookJsonObjectTest.java   
@Test
public void testGetValue ()
{
    JsonProvider provider = new CookJsonProvider ();
    JsonObjectBuilder builder = provider.createObjectBuilder ();
    JsonObject obj = builder
        .add ("string", "test")
        .add ("int", 1234)
        .add ("true", true)
        .add ("false", false)
        .addNull ("null")
        .add ("array", provider.createArrayBuilder ().build ())
        .add ("object", provider.createObjectBuilder ().build ())
        .build ();
    JsonValue v;
    v = obj.getJsonString ("string");
    Assert.assertEquals ("test", ((JsonString)v).getString ());
    v = obj.getJsonNumber ("int");
    Assert.assertEquals (1234, ((JsonNumber)v).intValue ());
    v = obj.get ("true");
    Assert.assertEquals (JsonValue.TRUE, v);
    v = obj.get ("false");
    Assert.assertEquals (JsonValue.FALSE, v);
    v = obj.get ("null");
    Assert.assertEquals (JsonValue.NULL, v);
    v = obj.getJsonArray ("array");
    Assert.assertEquals (ValueType.ARRAY, v.getValueType ());
    v = obj.getJsonObject ("object");
    Assert.assertEquals (ValueType.OBJECT, v.getValueType ());
}
项目:cookjson    文件:CookJsonArrayTest.java   
@Test
public void testGetValue ()
{
    JsonProvider provider = new CookJsonProvider ();
    JsonArrayBuilder builder = provider.createArrayBuilder ();
    JsonArray array = builder
        .add ("test")
        .add (1234)
        .add (true)
        .add (false)
        .addNull ()
        .add (provider.createArrayBuilder ().build ())
        .add (provider.createObjectBuilder ().build ())
        .build ();
    JsonValue v;
    v = array.getJsonString (0);
    Assert.assertEquals ("test", ((JsonString)v).getString ());
    v = array.getJsonNumber (1);
    Assert.assertEquals (1234, ((JsonNumber)v).intValue ());
    v = array.get (2);
    Assert.assertEquals (JsonValue.TRUE, v);
    v = array.get (3);
    Assert.assertEquals (JsonValue.FALSE, v);
    v = array.get (4);
    Assert.assertEquals (JsonValue.NULL, v);
    v = array.getJsonArray (5);
    Assert.assertEquals (ValueType.ARRAY, v.getValueType ());
    v = array.getJsonObject (6);
    Assert.assertEquals (ValueType.OBJECT, v.getValueType ());
}
项目:cookjson    文件:CookJsonStringTest.java   
@Test
public void test ()
{
    JsonString v = new CookJsonString ("test");
    Assert.assertEquals ("test", v.getString ());
    Assert.assertEquals ("test", v.getChars ());
    Assert.assertEquals ("\"test\"", v.toString ());
    Assert.assertEquals ("test".hashCode (), v.hashCode ());
    Assert.assertEquals (ValueType.STRING, v.getValueType ());
}
项目:hadoop-etl-udfs    文件:WebHCatJsonParser.java   
public static List<HCatSerDeParameter> parseSerDeParameters(JsonObject obj) {
    List<HCatSerDeParameter> serDeParameters = new ArrayList<>();
    for (Entry<String, JsonValue> serdeParam : obj.entrySet()) {
        assert(serdeParam.getValue().getValueType() == ValueType.STRING);
        serDeParameters.add(new HCatSerDeParameter(serdeParam.getKey(), ((JsonString)serdeParam.getValue()).getString()));
    }
    return serDeParameters;
}