Example usage for javax.json.stream JsonGenerator writeStartArray

List of usage examples for javax.json.stream JsonGenerator writeStartArray

Introduction

In this page you can find the example usage for javax.json.stream JsonGenerator writeStartArray.

Prototype

JsonGenerator writeStartArray();

Source Link

Document

Writes the JSON start array character.

Usage

From source file:at.porscheinformatik.sonarqube.licensecheck.mavenlicense.MavenLicense.java

public static String createString(Collection<MavenLicense> mavenLicenses) {
    TreeSet<MavenLicense> mavenLicenseSet = new TreeSet<>();
    mavenLicenseSet.addAll(mavenLicenses);

    StringWriter jsonString = new StringWriter();
    JsonGenerator generator = Json.createGenerator(jsonString);
    generator.writeStartArray();
    for (MavenLicense mavenLicense : mavenLicenseSet) {
        generator.writeStartObject();//from  w ww  .java2s.  com
        generator.write("licenseNameRegEx", mavenLicense.getLicenseNameRegEx().pattern());
        generator.write("license", mavenLicense.getLicense());
        generator.writeEnd();
    }
    generator.writeEnd();
    generator.close();

    return jsonString.toString();
}

From source file:at.porscheinformatik.sonarqube.licensecheck.license.License.java

public static String createString(Collection<License> licenses) {
    TreeSet<License> licenseSet = new TreeSet<>();
    licenseSet.addAll(licenses);//from   ww w  .j  a  v  a  2  s.co m

    StringWriter jsonString = new StringWriter();
    JsonGenerator generator = Json.createGenerator(jsonString);
    generator.writeStartArray();
    for (License license : licenseSet) {
        generator.writeStartObject();
        generator.write("name", license.getName());
        generator.write("identifier", license.getIdentifier());
        generator.write("status", license.getStatus());
        generator.writeEnd();
    }
    generator.writeEnd();
    generator.close();

    return jsonString.toString();
}