本文整理汇总了Java中javax.json.JsonValue.ValueType类的典型用法代码示例。如果您正苦于以下问题:Java ValueType类的具体用法?Java ValueType怎么用?Java ValueType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ValueType类属于javax.json.JsonValue包,在下文中一共展示了ValueType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAdapterNotes
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
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 "";
}
示例2: jsonToMap
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
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;
}
示例3: testInt
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
@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 ());
}
示例4: testLong
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
@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 ());
}
示例5: testDouble
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
@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 ());
}
示例6: testBigInteger
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
@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 ());
}
示例7: testBigDecimal
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
@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 ());
}
示例8: test
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
@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 ());
}
示例9: getJsonValue
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
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;
}
示例10: getAssetMap
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
/**
* 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;
}
示例11: getString
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
/**
* 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;
}
示例12: getLongArray
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
/**
* @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;
}
示例13: parseTagList
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
@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();
}
示例14: getEvent
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
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");
}
}
示例15: jsonAddedNode
import javax.json.JsonValue.ValueType; //导入依赖的package包/类
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;
}