/** * Convenience method for constructing {@link ObjectWriter} * with default settings. * * @since 1.6 */ public ObjectWriter writer() { return new ObjectWriter(this, copySerializationConfig()); }
/** * Factory method for constructing {@link ObjectWriter} that will * pass specific schema object to {@link JsonGenerator} used for * writing content. * * @param schema Schema to pass to generator * * @since 1.9 */ public ObjectWriter writer(FormatSchema schema) { return new ObjectWriter(this, copySerializationConfig(), schema); }
/** * Generate <a href="http://json-schema.org/">Json-schema</a> * instance for specified class. * * @param t The class to generate schema for * @return Constructed JSON schema. */ public JsonSchema generateJsonSchema(Class<?> t) throws JsonMappingException { return generateJsonSchema(t, copySerializationConfig()); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified root type, instead of actual * runtime type of value. Type must be a super-type of runtime type. * * @since 1.9 */ public ObjectWriter writerWithType(JavaType rootType) { return new ObjectWriter(this, copySerializationConfig(), rootType, /*PrettyPrinter*/null); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified pretty printer for indentation * (or if null, no pretty printer) * * @since 1.9 */ public ObjectWriter writer(PrettyPrinter pp) { if (pp == null) { // need to use a marker to indicate explicit disabling of pp pp = ObjectWriter.NULL_PRETTY_PRINTER; } return new ObjectWriter(this, copySerializationConfig(), /*root type*/ null, pp); }
/** * Method that can be called to check whether mapper thinks * it could serialize an instance of given Class. * Check is done * by checking whether a serializer can be found for the type. * * @return True if mapper can find a serializer for instances of * given class (potentially serializable), false otherwise (not * serializable) */ public boolean canSerialize(Class<?> type) { return _serializerProvider.hasSerializerFor(copySerializationConfig(), type, _serializerFactory); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified JSON View (filter). * * @since 1.9 */ public ObjectWriter writerWithView(Class<?> serializationView) { return new ObjectWriter(this, copySerializationConfig().withView(serializationView)); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using the default pretty printer for indentation * * @since 1.9 */ public ObjectWriter writerWithDefaultPrettyPrinter() { return new ObjectWriter(this, copySerializationConfig(), /*root type*/ null, _defaultPrettyPrinter()); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified {@link DateFormat}; or, if * null passed, using timestamp (64-bit number. * * @since 1.9 */ public ObjectWriter writer(DateFormat df) { return new ObjectWriter(this, copySerializationConfig().withDateFormat(df)); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified root type, instead of actual * runtime type of value. Type must be a super-type of runtime * type. * * @since 1.9 */ public ObjectWriter writerWithType(Class<?> rootType) { JavaType t = (rootType == null) ? null : _typeFactory.constructType(rootType); return new ObjectWriter(this, copySerializationConfig(), t, /*PrettyPrinter*/null); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified root type, instead of actual * runtime type of value. Type must be a super-type of runtime type. * * @since 1.9 */ public ObjectWriter writerWithType(TypeReference<?> rootType) { JavaType t = (rootType == null) ? null : _typeFactory.constructType(rootType); return new ObjectWriter(this, copySerializationConfig(), t, /*PrettyPrinter*/null); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified filter provider. * * @since 1.9 */ public ObjectWriter writer(FilterProvider filterProvider) { return new ObjectWriter(this, copySerializationConfig().withFilters(filterProvider)); }
/** * Method to serialize given JSON Tree, using generator * provided. */ @Override public void writeTree(JsonGenerator jgen, JsonNode rootNode) throws IOException, JsonProcessingException { SerializationConfig config = copySerializationConfig(); _serializerProvider.serializeValue(config, jgen, rootNode, _serializerFactory); if (config.isEnabled(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } }
/** * Method that can be used to serialize any Java value as * JSON output, using provided {@link JsonGenerator}. */ @Override public void writeValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException { SerializationConfig config = copySerializationConfig(); if (config.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) { _writeCloseableValue(jgen, value, config); } else { _serializerProvider.serializeValue(config, jgen, value, _serializerFactory); if (config.isEnabled(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } } }
protected final void _configAndWriteValue(JsonGenerator jgen, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException { SerializationConfig cfg = copySerializationConfig().withView(viewClass); if (cfg.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) { jgen.useDefaultPrettyPrinter(); } // [JACKSON-282]: consider Closeable if (cfg.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) { _configAndWriteCloseable(jgen, value, cfg); return; } boolean closed = false; try { _serializerProvider.serializeValue(cfg, jgen, value, _serializerFactory); closed = true; jgen.close(); } finally { if (!closed) { try { jgen.close(); } catch (IOException ioe) { } } } }
throws IOException, JsonGenerationException, JsonMappingException SerializationConfig cfg = copySerializationConfig();
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified root type, instead of actual * runtime type of value. Type must be a super-type of runtime type. * * @since 1.9 */ public ObjectWriter writerWithType(JavaType rootType) { return new ObjectWriter(this, copySerializationConfig(), rootType, /*PrettyPrinter*/null); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified {@link DateFormat}; or, if * null passed, using timestamp (64-bit number. * * @since 1.9 */ public ObjectWriter writer(DateFormat df) { return new ObjectWriter(this, copySerializationConfig().withDateFormat(df)); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified root type, instead of actual * runtime type of value. Type must be a super-type of runtime * type. * * @since 1.9 */ public ObjectWriter writerWithType(Class<?> rootType) { JavaType t = (rootType == null) ? null : _typeFactory.constructType(rootType); return new ObjectWriter(this, copySerializationConfig(), t, /*PrettyPrinter*/null); }
/** * Factory method for constructing {@link ObjectWriter} that will * serialize objects using specified root type, instead of actual * runtime type of value. Type must be a super-type of runtime type. * * @since 1.9 */ public ObjectWriter writerWithType(TypeReference<?> rootType) { JavaType t = (rootType == null) ? null : _typeFactory.constructType(rootType); return new ObjectWriter(this, copySerializationConfig(), t, /*PrettyPrinter*/null); }