本文整理汇总了Java中javax.json.JsonValue.ValueType方法的典型用法代码示例。如果您正苦于以下问题:Java JsonValue.ValueType方法的具体用法?Java JsonValue.ValueType怎么用?Java JsonValue.ValueType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.JsonValue
的用法示例。
在下文中一共展示了JsonValue.ValueType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueByPointer
import javax.json.JsonValue; //导入方法依赖的package包/类
/**
* Looks up a {@link JsonValue} which is referenced by a given JSON pointer.
* @param pointer the JSON pointer which refers to a {@link JsonValue}.
* @return the {@link JsonValue} if found, {@code null} otherwise.
* @exception IllegalArgumentException if specified pointer is {@code null}.
*/
public JsonValue getValueByPointer(JsonPointer pointer) {
if (pointer == null) {
throw new IllegalArgumentException();
}
JsonValue current = getRootValue();
for (Object token: pointer) {
if (current == null) {
break;
}
JsonValue.ValueType type = current.getValueType();
if (type == JsonValue.ValueType.ARRAY) {
if ((token instanceof Integer)) {
int index = ((Integer)token).intValue();
current = ((JsonArray)current).get(index);
} else {
current = null;
}
} else if (type == JsonValue.ValueType.OBJECT) {
current = ((JsonObject)current).get(token);
} else {
break;
}
}
return current;
}
示例2: compareJsonValue
import javax.json.JsonValue; //导入方法依赖的package包/类
private static void compareJsonValue(JsonValue actual, JsonValue expected) {
assertNotNull(actual);
assertNotNull(expected);
assertThat(actual.getValueType(), is(expected.getValueType()));
JsonValue.ValueType type = actual.getValueType();
if (type == JsonValue.ValueType.OBJECT) {
JsonObject actualObject = (JsonObject)actual;
JsonObject expectedObject = (JsonObject)expected;
assertThat(actualObject.size(), equalTo(expectedObject.size()));
for (String key: actualObject.keySet()) {
compareJsonValue(actualObject.get(key), expectedObject.get(key));
}
} else if (type == JsonValue.ValueType.ARRAY) {
JsonArray actualArray = (JsonArray)actual;
JsonArray expectedArray = (JsonArray)expected;
assertThat(actualArray.size(), equalTo(expectedArray.size()));
for (int i = 0; i < actualArray.size(); i++) {
compareJsonValue(actualArray.get(i), expectedArray.get(i));
}
} else {
assertTrue(actual.equals(expected));
}
}
示例3: createJsonString
import javax.json.JsonValue; //导入方法依赖的package包/类
/**
* Create a {@link JsonString}.
* <p>
* This is here mainly to support {@link #createJsonValue(java.lang.String)} as the {@link Json} class does not provide a way of generating this.
* <p>
* @param s String
* <p>
* @return JsonString
* <p>
* @throws NullPointerException if s is null
*/
public static JsonString createJsonString( final String s )
{
Objects.requireNonNull( s );
return new JsonString()
{
@Override
public String getString()
{
return s;
}
@Override
public CharSequence getChars()
{
return s;
}
@Override
public JsonValue.ValueType getValueType()
{
return JsonValue.ValueType.STRING;
}
};
}
示例4: printValue
import javax.json.JsonValue; //导入方法依赖的package包/类
/**
* This method prints the value of the JSON data. If the value is a JSON object and key1 is provided, it will
* only print the values of key1 and optionally key2. If key1 is null, it will recurse into the JSON object
* and print all the nested structures.
*
* @param key specifies the key string of the JSON object, can be null if no associated key.
* @param value specifies the JSON value.
* @param level specifies the indentation level.
* @param key1 specifies the first key.
* @param key2 specifies the second key.
* @param dataOut specifies the output print stream.
*/
private void printValue(String key, JsonValue value, int level, String key1, String key2, PrintStream dataOut)
{
JsonValue.ValueType valueType = value.getValueType();
switch (valueType)
{
case OBJECT:
JsonObject obj = (JsonObject)value;
printIndentation(level, dataOut);
if (key1 != null)
{
dataOut.print(obj.get(key1));
if (key2 != null)
{
dataOut.println(": " + obj.get(key2));
}
else
{
dataOut.println();
}
}
else
{
if (key != null)
{
dataOut.print(key + ": ");
}
dataOut.println("{");
Iterator<String> iterator = obj.keySet().iterator();
while (iterator.hasNext())
{
String childKey = iterator.next();
printValue(childKey, obj.get(childKey), level + 1, key1, key2, dataOut);
}
printIndentation(level, dataOut);
dataOut.println("}");
}
break;
case ARRAY:
printIndentation(level, dataOut);
if (key != null)
{
dataOut.print(key + ": ");
}
dataOut.println("[");
JsonArray array = (JsonArray)value;
for (int i = 0; i < array.size(); i++)
{
printValue(null, array.get(i), level + 1, key1, key2, dataOut);
}
printIndentation(level, dataOut);
dataOut.println("]");
break;
default:
printIndentation(level, dataOut);
if (key != null)
{
dataOut.print(key + ": ");
}
dataOut.println(value);
break;
}
}
示例5: createJsonNumber
import javax.json.JsonValue; //导入方法依赖的package包/类
public static JsonNumber createJsonNumber( BigDecimal d )
{
return new JsonNumber()
{
@Override
public boolean isIntegral()
{
return d.scale() == 0;
}
@Override
public int intValue()
{
return d.intValue();
}
@Override
public int intValueExact()
{
return d.intValueExact();
}
@Override
public long longValue()
{
return d.longValue();
}
@Override
public long longValueExact()
{
return d.longValueExact();
}
@Override
public BigInteger bigIntegerValue()
{
return d.toBigInteger();
}
@Override
public BigInteger bigIntegerValueExact()
{
return d.toBigIntegerExact();
}
@Override
public double doubleValue()
{
return d.doubleValue();
}
@Override
public BigDecimal bigDecimalValue()
{
return d;
}
@Override
public JsonValue.ValueType getValueType()
{
return ValueType.NUMBER;
}
};
}