/** * Returns a function (writer) converting {@link JsonStructure} to the {@link Flow.Publisher Publisher} * of {@link DataChunk}s. * * @param charset a charset to use or {@code null} for default charset * @return created function */ public Function<JsonStructure, Flow.Publisher<DataChunk>> writer(Charset charset) { return json -> { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JsonWriter writer = (charset == null) ? jsonWriterFactory.createWriter(baos) : jsonWriterFactory.createWriter(baos, charset); writer.write(json); writer.close(); return ContentWriters.byteArrayWriter(false) .apply(baos.toByteArray()); }; }
JsonWriter jsonWriter = Json.createWriter(stringWriter); jsonWriter.writeObject(jsonObject); jsonWriter.close();
String toJson(JsonObject toJsonFunc) { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(toJsonFunc); jsonWriter.close(); return stringWriter.toString(); }
String toJson() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(toJsonObject()); jsonWriter.close(); return stringWriter.toString(); }
public String toJson() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(toJsonObject()); jsonWriter.close(); return stringWriter.toString(); }
String toJson() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(toJsonObject()); jsonWriter.close(); return stringWriter.toString(); }
String toJson() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(this.toJsonObject()); jsonWriter.close(); return stringWriter.toString(); }
String toJson() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(toJsonObject()); jsonWriter.close(); return stringWriter.toString(); }
@Override public void writeTo(JsonValue jsonValue, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); JsonWriter writer = findWriter(mediaType, entityStream); try { writer.write(jsonValue); } finally { writer.close(); } }
@Override public void writeTo(JsonArray jsonValues, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); JsonWriter writer = findWriter(mediaType, entityStream); try { writer.writeArray(jsonValues); } finally { writer.close(); } } }
@Override public void writeTo(JsonStructure jsonStructure, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); JsonWriter writer = findWriter(mediaType, entityStream); try { writer.write(jsonStructure); } finally { writer.close(); } } }
@Override public void writeTo(JsonObject jsonObject, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); JsonWriter writer = findWriter(mediaType, entityStream); try { writer.writeObject(jsonObject); } finally { writer.close(); } } }
JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(jsonObject); jsonWriter.close(); String body = stringWriter.toString();
@Override public String toString() { StringWriter sw = new StringWriter(); JsonWriter jw = new JsonWriterImpl(sw, bufferPool); jw.write(this); jw.close(); return sw.toString(); } }
private static byte[] serialize(final JsonObject jsonObject) { try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { final Map<String, ?> config = singletonMap(JsonGenerator.PRETTY_PRINTING, true); final JsonWriter jsonWriter = Json.createWriterFactory(config).createWriter(output); jsonWriter.write(jsonObject); jsonWriter.close(); return output.toByteArray(); } catch (IOException e) { throw new RuntimeException("Could not write Swagger output", e); } }
private static byte[] serialize(final JsonObject jsonObject) { try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { final Map<String, ?> config = singletonMap(JsonGenerator.PRETTY_PRINTING, true); final JsonWriter jsonWriter = Json.createWriterFactory(config).createWriter(output); jsonWriter.write(jsonObject); jsonWriter.close(); return output.toByteArray(); } catch (IOException e) { throw new RuntimeException("Could not write Swagger output", e); } }
String toJson() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(toJsonObject()); jsonWriter.close(); return stringWriter.toString(); }
String toJson() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter)); jsonWriter.writeObject(toJsonObject()); jsonWriter.close(); return stringWriter.toString(); }
public void reportHealth(OutputStream out, SmallRyeHealth health) { JsonWriterFactory factory = Json.createWriterFactory(JSON_CONFIG); JsonWriter writer = factory.createWriter(out); writer.writeObject(health.getPayload()); writer.close(); }
@Benchmark @Override public Object javaxjson() throws Exception { javax.json.JsonObject jso = JSON_SOURCE().streamSerializer().javaxjson(JSON_SOURCE().nextPojo()); ByteArrayOutputStream baos = JsonUtils.byteArrayOutputStream(); javax.json.JsonWriter jw = javax.json.Json.createWriter(baos); jw.writeObject(jso); jw.close(); return baos; }