Search in sources :

Example 1 with JsonWriterFactory

use of jakarta.json.JsonWriterFactory in project glassfish-hk2 by eclipse-ee4j.

the class JsonParser method marshal.

/* (non-Javadoc)
     * @see org.glassfish.hk2.xml.spi.XmlServiceParser#marshall(java.io.OutputStream, org.glassfish.hk2.xml.api.XmlRootHandle)
     */
@Override
public <T> void marshal(OutputStream outputStream, XmlRootHandle<T> rootHandle, Map<String, Object> options) throws IOException {
    JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
    T root = rootHandle.getRoot();
    JsonObject rootObject = createJsonObject((BaseHK2JAXBBean) root, objectBuilder);
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
    JsonWriterFactory writerFactory = Json.createWriterFactory(config);
    JsonWriter writer = writerFactory.createWriter(outputStream);
    try {
        writer.writeObject(rootObject);
    } finally {
        writer.close();
    }
}
Also used : HashMap(java.util.HashMap) JsonObject(jakarta.json.JsonObject) JsonObject(jakarta.json.JsonObject) JsonObjectBuilder(jakarta.json.JsonObjectBuilder) JsonWriter(jakarta.json.JsonWriter) JsonWriterFactory(jakarta.json.JsonWriterFactory)

Aggregations

JsonObject (jakarta.json.JsonObject)1 JsonObjectBuilder (jakarta.json.JsonObjectBuilder)1 JsonWriter (jakarta.json.JsonWriter)1 JsonWriterFactory (jakarta.json.JsonWriterFactory)1 HashMap (java.util.HashMap)1