Java Code Examples for javax.json.JsonValue#ValueType

The following examples show how to use javax.json.JsonValue#ValueType . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphQLVariables.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
public Optional<Map<String, Object>> getVariables(JsonObject jsonInput) {
    if (!jsonInput.containsKey(VARIABLES)
            || jsonInput.get(VARIABLES) == null
            || jsonInput.get(VARIABLES).getValueType().equals(JsonValue.ValueType.NULL)) {
        return Optional.empty();
    }

    JsonValue.ValueType valueType = jsonInput.get(VARIABLES).getValueType();

    if (valueType.equals(JsonValue.ValueType.STRING)) {
        String stringVars = jsonInput.getString(VARIABLES);
        log.stringInputForVariables(stringVars);
        return Optional.empty();
    } else {
        JsonValue jvariables = jsonInput.get(VARIABLES);
        return getVariables(jvariables);
    }
}
 
Example 2
Source File: RawClaimTypeProducer.java    From smallrye-jwt with Apache License 2.0 6 votes vote down vote up
@Produces
@Claim("")
Boolean getClaimAsBoolean(InjectionPoint ip) {
    CDILogging.log.getClaimAsBoolean(ip);
    if (currentToken == null) {
        return null;
    }

    String name = getName(ip);
    Optional<Object> optValue = currentToken.claim(name);
    Boolean returnValue = null;
    if (optValue.isPresent()) {
        Object value = optValue.get();
        if (value instanceof JsonValue) {
            final JsonValue.ValueType valueType = ((JsonValue) value).getValueType();
            if (valueType.equals(JsonValue.ValueType.TRUE)) {
                returnValue = true;
            } else if (valueType.equals(JsonValue.ValueType.FALSE)) {
                returnValue = false;
            }
        } else {
            returnValue = Boolean.valueOf(value.toString());
        }
    }
    return returnValue;
}
 
Example 3
Source File: GenerateExtensionsJsonMojo.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private JsonObject mergeObject(JsonObject extObject, JsonObject extOverride) {
    final JsonObjectBuilder mergedObject = Json.createObjectBuilder(extObject);
    for (Map.Entry<String, JsonValue> e : extOverride.entrySet()) {
        JsonValue.ValueType tp = e.getValue().getValueType();
        if (tp == JsonValue.ValueType.OBJECT
                && extObject.containsKey(e.getKey())
                && extObject.get(e.getKey()).getValueType() == JsonValue.ValueType.OBJECT) {
            mergedObject.add(e.getKey(),
                    mergeObject(extObject.get(e.getKey()).asJsonObject(), e.getValue().asJsonObject()));
        } else if (tp == JsonValue.ValueType.ARRAY) {
            final JsonArrayBuilder newArray = Json.createArrayBuilder(e.getValue().asJsonArray());
            mergedObject.add(e.getKey(), newArray.build());
        } else {
            mergedObject.add(e.getKey(), e.getValue());
        }
    }
    return mergedObject.build();
}
 
Example 4
Source File: GraphQLVariables.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
private Object toObject(JsonValue jsonValue) {
    Object ret = null;
    JsonValue.ValueType typ = jsonValue.getValueType();
    if (null != typ)
        switch (typ) {
            case NUMBER:
                ret = ((JsonNumber) jsonValue).bigDecimalValue();
                break;
            case STRING:
                ret = ((JsonString) jsonValue).getString();
                break;
            case FALSE:
                ret = Boolean.FALSE;
                break;
            case TRUE:
                ret = Boolean.TRUE;
                break;
            case ARRAY:
                JsonArray arr = (JsonArray) jsonValue;
                List<Object> vals = new ArrayList<>();
                int sz = arr.size();
                for (int i = 0; i < sz; i++) {
                    JsonValue v = arr.get(i);
                    vals.add(toObject(v));
                }
                ret = vals;
                break;
            case OBJECT:
                ret = toMap((JsonObject) jsonValue);
                break;
            default:
                break;
        }
    return ret;
}
 
Example 5
Source File: VertxJson.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static void copy(JsonArray array, javax.json.JsonArray origin) {
    for (int i = 0; i < origin.size(); i++) {
        JsonValue value = origin.get(i);
        JsonValue.ValueType kind = value.getValueType();
        switch (kind) {
            case STRING:
                array.add(origin.getString(i));
                break;
            case TRUE:
                array.add(true);
                break;
            case FALSE:
                array.add(false);
                break;
            case NULL:
                array.addNull();
                break;
            case NUMBER:
                JsonNumber number = origin.getJsonNumber(i);
                if (number.isIntegral()) {
                    array.add(number.longValue());
                } else {
                    array.add(number.doubleValue());
                }
                break;
            case ARRAY:
                JsonArray newArray = new JsonArray();
                copy(newArray, origin.getJsonArray(i));
                array.add(newArray);
                break;
            case OBJECT:
                JsonObject newObject = new JsonObject();
                copy(newObject, origin.getJsonObject(i));
                array.add(newObject);
                break;
            default:
                throw new IllegalArgumentException("Unknown JSON Value " + kind);
        }
    }
}
 
Example 6
Source File: GenerateReleaseNotesTask.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
protected String commitToGithubMention(RepoCommits commitsClient,
		SimpleCommit revCommit) {
	RepoCommit dumbCommit = commitsClient.get(revCommit.fullSha1);
	RepoCommit.Smart smartCommit = new RepoCommit.Smart(dumbCommit);
	try {
		JsonObject commitJson = smartCommit.json();
		JsonValue.ValueType authorType = commitJson.get("author").getValueType();
		if (authorType == JsonValue.ValueType.OBJECT) {
			return "@" + commitJson.getJsonObject("author").getString("login");
		}
		else if (authorType == JsonValue.ValueType.NULL) {
			// assume author+committer, look under commit.author.name
			if (commitJson.containsKey("commit")
					&& commitJson.getJsonObject("commit").containsKey("author")) {
				return "@" + commitJson.getJsonObject("commit")
						.getJsonObject("author").getString("name");
			}
		}
		// in case unexpected json, output the "sha", "commit", "author" and
		// "committer"
		return "@RAW{\"sha\", " + commitJson.get("sha") + ", \"author\", \""
				+ commitJson.get("author") + ", \"committer\", \""
				+ commitJson.get("committer") + ", \"commit\", \""
				+ commitJson.get("commit") + "}";
	}
	catch (IOException e) {
		return null;
	}
}