ObjectWriter newOutputWriter(boolean serializeDateTimeAsLong) { ObjectMapper mapper = serializeDateTimeAsLong ? serializeDateTimeAsLongInputMapper : inputMapper; return isPretty ? mapper.writerWithDefaultPrettyPrinter() : mapper.writer(); }
/** * Provides the ObjectWriter, with which objects are serialized to JSON form. This method may be overridden to * change the configuration of the writer to use. * * @return The writer to serialize objects with */ protected ObjectWriter getWriter() { return objectMapper.writer(); }
/** * Convert a Java object to a JMS Message using the specified json view * and the supplied session to create the message object. * @param object the object to convert * @param session the Session to use for creating a JMS Message * @param jsonView the view to use to filter the content * @return the JMS Message * @throws javax.jms.JMSException if thrown by JMS API methods * @throws MessageConversionException in case of conversion failure * @since 4.3 */ public Message toMessage(Object object, Session session, @Nullable Class<?> jsonView) throws JMSException, MessageConversionException { if (jsonView != null) { return toMessage(object, session, this.objectMapper.writerWithView(jsonView)); } else { return toMessage(object, session, this.objectMapper.writer()); } }
public static ObjectWriter writer() { return OBJECT_MAPPER.writer(); }
private ObjectWriter getWriter(HttpServletRequest request) { ObjectMapper objectMapperCopy = mapper.copy(); registerMetricsRegistryModule(request, objectMapperCopy); if (Boolean.parseBoolean(request.getParameter("pretty"))) { return objectMapperCopy.writerWithDefaultPrettyPrinter(); } return objectMapperCopy.writer(); }
/** * 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 Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { Message message; try { switch (this.targetType) { case TEXT: message = mapToTextMessage(object, session, this.objectMapper.writer()); break; case BYTES: message = mapToBytesMessage(object, session, this.objectMapper.writer()); break; default: message = mapToMessage(object, session, this.objectMapper.writer(), this.targetType); } } catch (IOException ex) { throw new MessageConversionException("Could not map JSON object [" + object + "]", ex); } setTypeIdOnMessage(object, message); return message; }
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null); ObjectWriter writer = (jsonView != null ? getObjectMapper().writerWithView(jsonView) : getObjectMapper().writer());
private void sendMessage(Message message) { if (exchange == null) { return; } try { exchange.send(mapper.writer().writeValueAsString(message)); } catch (IOException e) { throw new RuntimeException(e); } }
this.objectMapper.writerWithView(serializationView) : this.objectMapper.writer()); if (filters != null) { objectWriter = objectWriter.with(filters);
private Path write(Path output, List<RouteMethod> routes) throws IOException { Files.createDirectories(output.getParent()); log.debug("writing {} with {}", output, routes); mapper.writer().withDefaultPrettyPrinter().writeValue(output.toFile(), routes); return output; }
private AsynchronousAgentDispatcher() { this.writer = new ObjectMapper() .setSerializationInclusion(JsonInclude.Include.NON_NULL) .setPropertyNamingStrategy(new PropertyNamingStrategy.PascalCaseStrategy()) .writer(); }
private byte[] writeObject(Object o) { try { return this.mapper.writer().writeValueAsBytes(o); } catch (JsonProcessingException e) { throw new AssertionError(e); } }
public ObjectLinesWriter(final OutputStream outputStream, final ObjectMapper jsonMapper) throws IOException { this.outputStream = outputStream; this.jsonGenerator = jsonMapper.writer().getFactory().createGenerator(outputStream); jsonGenerator.setRootValueSeparator(new SerializedString("\n")); }
public ArrayLinesWriter(final OutputStream outputStream, final ObjectMapper jsonMapper) throws IOException { this.outputStream = outputStream; this.jsonGenerator = jsonMapper.writer().getFactory().createGenerator(outputStream); jsonGenerator.setRootValueSeparator(new SerializedString("\n")); }
public static ObjectWriter pretty() { return mapper().writer(new DefaultPrettyPrinter()); }
public static ObjectWriter pretty() { return mapper().writer(new DefaultPrettyPrinter()); }
protected void prettyPrint(Object o) { try { System.out.println(mapper().writer(new DefaultPrettyPrinter()).writeValueAsString(o)); } catch (Exception e) { e.printStackTrace(); } } }
@Before public void setUp() { log4jObjectMapper = newObjectMapper(); writer = log4jObjectMapper.writer(); reader = log4jObjectMapper.readerFor(Level.class); }
@Before public void setUp() { final ObjectMapper log4jObjectMapper = newObjectMapper(); writer = log4jObjectMapper.writer(); reader = log4jObjectMapper.readerFor(Log4jMarker.class); MarkerManager.clear(); }