Java Code Examples for com.eclipsesource.json.Json#object()

The following examples show how to use com.eclipsesource.json.Json#object() . 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: TestPlatformJsonDescriptorProvider.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Path getPath(Path workDir) throws IOException {
    final Model model = bomArtifact.getPomModel();

    final JsonObject json = Json.object();

    json.set("bom", Json.object().set("groupId", model.getGroupId()).set("artifactId", model.getArtifactId()).set("version",
            model.getVersion()));

    String coreVersion = null;
    for (Dependency dep : model.getDependencyManagement().getDependencies()) {
        if (dep.getArtifactId().equals(ToolsConstants.QUARKUS_CORE_ARTIFACT_ID)
                && dep.getGroupId().equals(ToolsConstants.QUARKUS_CORE_GROUP_ID)) {
            coreVersion = dep.getVersion();
        }
    }
    if (coreVersion == null) {
        throw new IllegalStateException("Failed to locate " + ToolsConstants.QUARKUS_CORE_GROUP_ID + ":"
                + ToolsConstants.QUARKUS_CORE_ARTIFACT_ID + " among the managed dependencies");
    }
    json.set("quarkus-core-version", coreVersion);

    final Path jsonPath = workDir.resolve(bomArtifact.getArtifactFileName());
    try (BufferedWriter writer = Files.newBufferedWriter(jsonPath)) {
        json.writeTo(writer);
    }
    return jsonPath;
}
 
Example 2
Source File: AccessToken.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public static ModelAndView doLogin(Authenticator auth, String username, String password) {
	String token = auth.authenticate(username, password);
	ModelAndView result = new ModelAndView();
	if (token == null) {
		result.setData(new ValidationResult("Invalid login or password").toJson());
		result.setStatus(Response.Status.UNAUTHORIZED);
	} else {
		JsonObject data = Json.object();
		data.add("access_token", token);
		data.add("token_type", "bearer");
		data.add("expires_in", auth.getMaxAgeMillis() / 1000);
		result.setData(data.toString());
	}
	return result;
}
 
Example 3
Source File: ValidationResult.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public String toJson() {
	JsonObject result = Json.object();
	if (!isEmpty()) {
		JsonObject errors = Json.object();
		if (general != null) {
			errors.add("general", general);
		}
		for (Entry<String, String> cur : entrySet()) {
			errors.add(cur.getKey(), cur.getValue());
		}
		result.add("errors", errors);
	}
	return result.toString();
}