/** * A Jackson JSON writer. Pretty print is off. * @return JSON object writer with indentation disabled */ public static ObjectWriter getJsonWriterNoIdent() { return jsonWriter.without(SerializationFeature.INDENT_OUTPUT); }
public static ObjectWriter jsonWriter() throws IOException { return jsonMapper().writerFor(DistributionSnapshot.class) .withoutRootName() .with(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM) .without(JsonGenerator.Feature.AUTO_CLOSE_TARGET); }
.with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) .with(JsonGenerator.Feature.QUOTE_FIELD_NAMES) .without(SerializationFeature.FAIL_ON_EMPTY_BEANS) .withoutFeatures(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS)); GuiceContext.get(DefaultObjectMapper) .writer() .without(SerializationFeature.INDENT_OUTPUT) .with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) .with(JsonGenerator.Feature.QUOTE_FIELD_NAMES) .without(SerializationFeature.FAIL_ON_EMPTY_BEANS) .withoutFeatures(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS));
/** * A Jackson JSON writer. Pretty print is off. * * @return JSON object writer with indentation disabled */ public static ObjectWriter getJsonWriterNoIdent() { return JSON_MAPPER.writer().without(SerializationFeature.INDENT_OUTPUT); }
.with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) .with(JsonGenerator.Feature.QUOTE_FIELD_NAMES) .without(SerializationFeature.FAIL_ON_EMPTY_BEANS) .withoutFeatures(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS)); GuiceContext.get(DefaultObjectMapper) .writer() .without(SerializationFeature.INDENT_OUTPUT) .with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) .with(JsonGenerator.Feature.QUOTE_FIELD_NAMES) .without(SerializationFeature.FAIL_ON_EMPTY_BEANS) .withoutFeatures(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS));
/** * Configures json with the given properties * * @param jsonObjectMapper */ private ObjectWriter configureObjectMapperForCSS(ObjectWriter jsonObjectMapper) { jsonObjectMapper = jsonObjectMapper.without(SerializationFeature.INDENT_OUTPUT); jsonObjectMapper = jsonObjectMapper.with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); jsonObjectMapper = jsonObjectMapper.without(JsonGenerator.Feature.QUOTE_FIELD_NAMES); return jsonObjectMapper; }
@PostConstruct public void postConstruct() { this.objectWriter = objectMapper.writer().without(JsonGenerator.Feature.AUTO_CLOSE_TARGET); }
@SuppressWarnings("deprecation") public SwaggerService() { mapper = Json.mapper(); writer = mapper.writerWithDefaultPrettyPrinter(); writer = writer.without(SerializationFeature.WRITE_NULL_MAP_VALUES); yamlMapper = Yaml.mapper(); }
public BackgroundMetricsAccessor(SharedServiceStuff stuff, Stores<?,?> stores, AllOperationMetrics.Provider[] metricsProviders) { _timeMaster = stuff.getTimeMaster(); _entryStore = stores.getEntryStore(); _lastAccessStore = stores.getLastAccessStore(); _metricsProviders = metricsProviders; /* 16-May-2013, tatu: Need to use separate mapper just because * our default inclusion mechanism may differ... */ ObjectMapper mapper = new ObjectMapper(); /* Looks like NON_DEFAULT can not be used, just because not all * classes can be instantiated. So for now need to use NON_EMPTY... */ mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); _jsonWriter = mapper.writerWithType(ExternalMetrics.class) .without(SerializationFeature.FAIL_ON_EMPTY_BEANS); }
/** * Serialize the given value to byte string using the given mapper, employing the given codec algorithm. * * @param mapper object mapper * @param value value to serialize * @param codec codec * @return serialized bytes * @throws JsonGenerationException in case of serialization errors */ public static ByteString writeValue(ObjectMapper mapper, Object value, Codec codec) throws JsonGenerationException { final Output output = ByteString.newOutput(); try { final OutputStream os = codec.compress(output); try { mapper.writer() .without(SerializationFeature.INDENT_OUTPUT) .writeValue(os, value); } finally { os.close(); } } catch (IOException e) { // Should not happen but... throw new JsonGenerationException(e, null); } // Javadoc says data is copied, but it's more of a transfer of ownership! return output.toByteString(); }
ObjectWriter writer = mapper.writer().without(JsonGenerator.Feature.AUTO_CLOSE_TARGET); boolean notPlainText = false; if (request instanceof DocumentRequest) {
@Override protected ObjectWriter createObjectWriter() { ObjectWriter writer = super.createObjectWriter(); for (SerializationFeature feature : SerializationFeature.values()) { boolean hasDefault = DEFAULT_SERIALIZATION_FEATURES.contains(feature); Parameter parameter = ContextUtils.getParameter(ContextUtils.getCurrentApplicationContext(), SERIALIZATION_FEATURE + feature.name()); if ((parameter != null) || hasDefault) { if (ContextUtils.getParameterAsBoolean(parameter, feature.enabledByDefault() || hasDefault)) { writer = writer.with(feature); } else { writer = writer.without(feature); } } } return writer; } }
@Test public void vavr_List_DateTime_serialization_should_use_SerializationFeature() throws IOException { final DateTime dateTime = new DateTime(2016, 6, 6, 8, 0, DateTimeZone.forID("CET")); final io.vavr.collection.List<DateTime> dateTimeList = List.of(dateTime); final java.util.List<DateTime> dateTimeJavaList = new ArrayList<>(); dateTimeJavaList.add(dateTime); final CsvMapper mapper = getMapper(); final ObjectWriter writer = mapper.writer() .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); final String serializedDateTime = writer .writeValueAsString(dateTime); final String serializedDateTimeJavaList = writer .writeValueAsString(dateTimeJavaList); final String serializedDateTimeList = writer .writeValueAsString(dateTimeList); Assert.assertEquals(serializedDateTime, serializedDateTimeJavaList); Assert.assertEquals(serializedDateTimeJavaList, serializedDateTimeList); List<DateTime> restored = mapper.readValue(serializedDateTimeList, new TypeReference<List<DateTime>>() {}); Assert.assertEquals(restored.head().getMillis(), dateTime.getMillis()); } }
ObjectWriter writer = mapper.writer().without(JsonGenerator.Feature.AUTO_CLOSE_TARGET); byte[] json = writer.writeValueAsBytes(admReq.getText()); insBody = new ByteArrayBody(json, ContentType.parse(AdmRequest.ADM_CONTENT_TYPE), null);