public static void write(Object value, Writer w) throws JsonGenerationException, JsonMappingException, IOException { WRITER.writeValue(w, value); }
/** * Utility function good for testing things. Prints out the json tree of the * JmxProcess. */ public void prettyPrint(JmxProcess process) throws Exception { prettyPrintingWriter.writeValue(out, process); } }
/** * Map the given object to a {@link TextMessage}. * @param object the object to be mapped * @param session current JMS session * @param objectWriter the writer to use * @return the resulting message * @throws JMSException if thrown by JMS methods * @throws IOException in case of I/O errors * @since 4.3 * @see Session#createBytesMessage */ protected TextMessage mapToTextMessage(Object object, Session session, ObjectWriter objectWriter) throws JMSException, IOException { StringWriter writer = new StringWriter(); objectWriter.writeValue(writer, object); return session.createTextMessage(writer.toString()); }
public <T> void writeTo(T object, OutputStream entityStream) throws IOException { ObjectWriter writer = objectWriterByClass.get(object.getClass()); if (writer == null) { mapper.writeValue(entityStream, object); } else { writer.writeValue(entityStream, object); } }
private void writeStatistics(Path path, TableStatisticsData tableStatisticsData) { File file = path.toFile(); file.getParentFile().mkdirs(); try { objectMapper .writerWithDefaultPrettyPrinter() .writeValue(file, tableStatisticsData); try (FileWriter fileWriter = new FileWriter(file, true)) { fileWriter.append('\n'); } } catch (IOException e) { throw new RuntimeException("Could not save table statistics data", e); } }
private void writeStatistics(Path path, TableStatisticsData tableStatisticsData) { File file = path.toFile(); file.getParentFile().mkdirs(); try { objectMapper .writerWithDefaultPrettyPrinter() .writeValue(file, tableStatisticsData); try (FileWriter fileWriter = new FileWriter(file, true)) { fileWriter.append('\n'); } } catch (IOException e) { throw new RuntimeException("Could not save table statistics data", e); } }
/** * Map the given object to a {@link BytesMessage}. * @param object the object to be mapped * @param session current JMS session * @param objectWriter the writer to use * @return the resulting message * @throws JMSException if thrown by JMS methods * @throws IOException in case of I/O errors * @since 4.3 * @see Session#createBytesMessage */ protected BytesMessage mapToBytesMessage(Object object, Session session, ObjectWriter objectWriter) throws JMSException, IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); OutputStreamWriter writer = new OutputStreamWriter(bos, this.encoding); objectWriter.writeValue(writer, object); BytesMessage message = session.createBytesMessage(); message.writeBytes(bos.toByteArray()); if (this.encodingPropertyName != null) { message.setStringProperty(this.encodingPropertyName, this.encoding); } return message; }
@Override public void writeValue(OutputStream out, Object value) throws IOException, JsonGenerationException, JsonMappingException { writerFor(type).with(schema).writeValue(out, value); } @Override
@Override public void writeValue(OutputStream out, Object value) throws IOException, JsonGenerationException, JsonMappingException { writerFor(type).with(schema).writeValue(out, value); } @Override
JsonGenerator generator = this.objectMapper.getFactory().createGenerator(out, encoding); if (view != null) { this.objectMapper.writerWithView(view).writeValue(generator, payload); Writer writer = new StringWriter(); if (view != null) { this.objectMapper.writerWithView(view).writeValue(writer, payload);
private void printAsJson(final Object o) throws IOException { if (!((o instanceof PropertiesList || (o instanceof KsqlEntityList)))) { log.warn( "Unexpected result class: '{}' found in printAsJson", o.getClass().getCanonicalName() ); } objectMapper.writerWithDefaultPrettyPrinter().writeValue(writer(), o); writer().println(); flush(); }
@Override public void onCompleteResponse(final HttpRequest request, final HttpResponse response) { try { ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); Session targetSession = Session.newSession(request, response); writer.writeValue(this.file, prepareTargetSessions(this.file, targetSession)); } catch (IOException e) { throw new MocoException(e); } }
@Override public void onSuccess(List<SegmentLoadDropHandler.DataSegmentChangeRequestAndStatus> result) { try { HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse(); response.setStatus(HttpServletResponse.SC_OK); context.inputMapper.writerWithType(HttpLoadQueuePeon.RESPONSE_ENTITY_TYPE_REF) .writeValue(asyncContext.getResponse().getOutputStream(), result); asyncContext.complete(); } catch (Exception ex) { log.debug(ex, "Request timed out or closed already."); } }
/** * Write the actual JSON content to the stream. * @param stream the output stream to use * @param object the value to be rendered, as returned from {@link #filterModel} * @throws IOException if writing failed */ protected void writeContent(OutputStream stream, Object object) throws IOException { JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding); writePrefix(generator, object); Object value = object; Class<?> serializationView = null; FilterProvider filters = null; if (value instanceof MappingJacksonValue) { MappingJacksonValue container = (MappingJacksonValue) value; value = container.getValue(); serializationView = container.getSerializationView(); filters = container.getFilters(); } ObjectWriter objectWriter = (serializationView != null ? this.objectMapper.writerWithView(serializationView) : this.objectMapper.writer()); if (filters != null) { objectWriter = objectWriter.with(filters); } objectWriter.writeValue(generator, value); writeSuffix(generator, object); generator.flush(); }
@Override public void onSuccess(ChangeRequestsSnapshot<DataSegmentChangeRequest> result) { try { HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse(); response.setStatus(HttpServletResponse.SC_OK); context.inputMapper.writerWithType(HttpServerInventoryView.SEGMENT_LIST_RESP_TYPE_REF) .writeValue(asyncContext.getResponse().getOutputStream(), result); asyncContext.complete(); } catch (Exception ex) { log.debug(ex, "Request timed out or closed already."); } }
@Override public void onSuccess(ChangeRequestsSnapshot result) { try { HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse(); response.setStatus(HttpServletResponse.SC_OK); context.inputMapper.writerWithType(WorkerHolder.WORKER_SYNC_RESP_TYPE_REF) .writeValue(asyncContext.getResponse().getOutputStream(), result); asyncContext.complete(); } catch (Exception ex) { log.debug(ex, "Request timed out or closed already."); } }
@Override public void encode(BsonWriter writer, T value, EncoderContext encoderContext) { final BsonGenerator generator = new BsonGenerator(0, mapper, writer); try { mapper.writerFor(getEncoderClass()).writeValue(generator, value); } catch (IOException e) { throw new RuntimeException("Couldn't serialize [" + value + "] as " + getEncoderClass(), e); } }
private synchronized void persistSequences() throws IOException { log.info("Persisting Sequences Metadata [%s]", sequences); toolbox.getObjectMapper().writerWithType( new TypeReference<List<SequenceMetadata>>() { } ).writeValue(getSequencesPersistFile(toolbox), sequences); }
JsonGenerator generator = getObjectMapper().getFactory().createGenerator(outputStream, encoding); writer.writeValue(generator, value); release = false;
objectWriter = objectWriter.with(this.ssePrettyPrinter); objectWriter.writeValue(generator, value);