本文整理汇总了Java中javax.json.JsonValue类的典型用法代码示例。如果您正苦于以下问题:Java JsonValue类的具体用法?Java JsonValue怎么用?Java JsonValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonValue类属于javax.json包,在下文中一共展示了JsonValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAdapterNotes
import javax.json.JsonValue; //导入依赖的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: toJSON
import javax.json.JsonValue; //导入依赖的package包/类
/**
* Turn this into jet json
* @return json
*/
@Override
public JsonObject toJSON()
{
final JsonObjectBuilder b = Json.createObjectBuilder();
for ( Map.Entry<String,JsonValue> entry : super.toJSON().entrySet())
{
if ( entry.getKey().equals( "return_refund_feedback" ))
b.add( "refund_feedback", entry.getValue());
else
b.add( entry.getKey(), entry.getValue());
}
b.add( "refund_reason", refundReason.getText());
return b.build();
}
示例3: 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;
}
示例4: signUp
import javax.json.JsonValue; //导入依赖的package包/类
@Override
public User signUp() {
final JsonArray registered = this.server.storage().build()
.getJsonArray("users");
final JsonArrayBuilder users = Json.createArrayBuilder();
for(final JsonValue user: registered) {
users.add(user);
}
users.add(
Json.createObjectBuilder()
.add(
this.json.getString("username"),
this.json
)
);
this.server.storage().add("users", users.build());
return new MkUser(this.server, this.json.getString("username"));
}
示例5: convert
import javax.json.JsonValue; //导入依赖的package包/类
private void convert(JsonValue json) {
if (json == null) {
builder.append("null");
return;
}
if (json instanceof JsonObject) {
convert(((JsonObject) json));
return;
}
if (json instanceof JsonArray) {
convert(((JsonArray) json));
return;
}
builder.append(json.toString());
}
示例6: addValue
import javax.json.JsonValue; //导入依赖的package包/类
public static void addValue(JsonObjectBuilder obj, String key, Object value) {
if (value instanceof Integer) {
obj.add(key, (Integer)value);
}
else if (value instanceof String) {
obj.add(key, (String)value);
}
else if (value instanceof Float) {
obj.add(key, (Float)value);
}
else if (value instanceof Double) {
obj.add(key, (Double)value);
}
else if (value instanceof Boolean) {
obj.add(key, (Boolean)value);
}
else if (value instanceof JsonValue) {
JsonValue val = (JsonValue)value;
obj.add(key, val);
}
// Add more cases here
}
示例7: addTeams
import javax.json.JsonValue; //导入依赖的package包/类
/**
* This method adds teams of the specified page to the teams array.
*
* @param arrBuilder specifies the array builder to add the teams into.
* @param year specifies the optional year, null for all years.
* @param pageNum specifies the page number.
* @param verbosity specifies optional verbosity, null for full verbosity.
* @param statusOut specifies standard output stream for command status, can be null for quiet mode.
* @return true if successful, false if failed.
*/
private boolean addTeams(
JsonArrayBuilder arrBuilder, String year, int pageNum, String verbosity, PrintStream statusOut)
{
String request = "teams/";
if (year != null) request += year + "/";
request += pageNum;
if (verbosity != null) request += "/" + verbosity;
JsonStructure data = get(request, statusOut, header);
boolean success;
if (data != null && data.getValueType() == JsonValue.ValueType.ARRAY && !((JsonArray)data).isEmpty())
{
for (JsonValue team: (JsonArray)data)
{
arrBuilder.add(team);
}
success = true;
}
else
{
success = false;
}
return success;
}
示例8: JwksResponse
import javax.json.JsonValue; //导入依赖的package包/类
JwksResponse(JsonObject jsonObject)
{
JsonValue keys = jsonObject.get("keys");
if (keys.getValueType() != JsonValue.ValueType.ARRAY)
{
_keys = Collections.emptyList();
}
else
{
_keys = Stream.of((JsonArray)keys)
.filter(it -> it.getValueType() == JsonValue.ValueType.OBJECT)
.map(it -> (JsonObject) it)
.map(JsonWebKey::new)
.collect(Collectors.toList());
}
}
示例9: toJavaObject
import javax.json.JsonValue; //导入依赖的package包/类
/**
* Converts a {@link JsonValue} to its corresponding Java object. Values of type {@link
* JsonObject} or {@link JsonArray} are converted as specified by {@link #toJavaMap} and {@link
* #toJavaList}, respectively.
*/
@Nullable
public static Object toJavaObject(JsonValue value) {
switch (value.getValueType()) {
case ARRAY:
return toJavaList((JsonArray) value);
case FALSE:
return Boolean.FALSE;
case NULL:
return null;
case NUMBER:
JsonNumber number = (JsonNumber) value;
return number.isIntegral() ? number.intValue() : number.doubleValue();
case OBJECT:
return toJavaMap((JsonObject) value);
case STRING:
return ((JsonString) value).getString();
case TRUE:
return Boolean.TRUE;
default:
throw new VerifyException("Json value with unknown type: " + value);
}
}
示例10: toJavaMap
import javax.json.JsonValue; //导入依赖的package包/类
/**
* Converts a {@link JsonObject} to a map from names to objects returned by {@link #toJavaObject}.
* The returned map is a mutable copy that will never have null keys but may have null values.
*/
public static Map<String, Object> toJavaMap(JsonObject object) {
Map<String, Object> map = new LinkedHashMap<>();
for (Entry<String, JsonValue> e : object.entrySet()) {
map.put(e.getKey(), toJavaObject(e.getValue()));
}
return map;
}
示例11: handle
import javax.json.JsonValue; //导入依赖的package包/类
@Override
public Response handle() throws Exception {
String ref = getRequest().getVariableValue(":reference");
RemoteWebElement element = getWebDriver().createElement(ref);
JsonArray array = getRequest().getPayload().getJsonArray("value");
String value = "";
for (JsonValue jsonValue : array) {
value += JavaxJson.toJavaObject(jsonValue);
}
element.setValueAtoms(value);
Response res = new Response();
res.setSessionId(getSession().getSessionId());
res.setStatus(0);
res.setValue(new JSONObject());
return res;
}
示例12: findCustomerByAddress
import javax.json.JsonValue; //导入依赖的package包/类
public void findCustomerByAddress() {
searchResult = null;
String text = "/" + this.addressSearchText;
JsonObject json = Json.createObjectBuilder().build();
JsonValue object = json.getJsonObject(fetchJson());
if (addressSearchText != null) {
JsonPointer pointer = Json.createPointer(text);
JsonValue result = pointer.getValue(object.asJsonArray());
// Replace a value
JsonArray array = (JsonArray) pointer.replace(object.asJsonArray(), Json.createValue("1000 JsonP Drive"));
searchResult = array.toString();
//searchResult = result.toString();
}
}
示例13: unbox
import javax.json.JsonValue; //导入依赖的package包/类
public static Object unbox(JsonValue value, Function<JsonStructure, Object> convert) throws JsonException {
switch (value.getValueType()) {
case ARRAY:
case OBJECT:
return convert.apply((JsonStructure) value);
case FALSE:
return Boolean.FALSE;
case TRUE:
return Boolean.TRUE;
case NULL:
return null;
case NUMBER:
JsonNumber number = (JsonNumber) value;
return number.isIntegral() ? number.longValue() : number.doubleValue();
case STRING:
return ((JsonString) value).getString();
default:
throw new JsonException("Unknow value type");
}
}
示例14: save
import javax.json.JsonValue; //导入依赖的package包/类
public JsonObject save(JsonObject input, String href, String date) {
String id = href.substring(href.lastIndexOf('/') +1);
JsonObjectBuilder builder = Json.createObjectBuilder();
builder.add("id", id);
builder.add("date", date);
JsonObject jsonLink = Json.createObjectBuilder()
.add("rel", Json.createArrayBuilder().add("self").build())
.add("href", href)
.build();
builder.add("links", jsonLink);
for (Map.Entry<String, JsonValue> entry : input.entrySet()) {
builder.add(entry.getKey(), entry.getValue());
}
JsonObject storedObject = builder.build();
exampleStore.put(id, storedObject);
return storedObject;
}
示例15: plainifyJsonValue
import javax.json.JsonValue; //导入依赖的package包/类
private Object plainifyJsonValue(final JsonValue jval) {
switch (jval.getValueType()) {
case ARRAY:
return plainifyJsonArray((JsonArray) jval);
case FALSE:
return Boolean.FALSE;
case TRUE:
return Boolean.TRUE;
case NULL:
return null;
case NUMBER:
return ((JsonNumber) jval).bigDecimalValue();
case OBJECT:
return plainifyJsonObject((JsonObject) jval);
case STRING:
return ((JsonString) jval).getString();
default:
throw new RuntimeException("unexpected json type");
}
}