/** * Constructor used by {@link ObjectMapper} for initial instantiation */ protected ObjectWriter(ObjectMapper mapper, SerializationConfig config, JavaType rootType, PrettyPrinter pp) { _config = config; _serializerProvider = mapper._serializerProvider; _serializerFactory = mapper._serializerFactory; _jsonFactory = mapper._jsonFactory; _rootType = rootType; _prettyPrinter = pp; _schema = null; _rootSerializer = _prefetchRootSerializer(config, rootType); }
/** * Method that will construct a new instance that uses specific type * as the root type for serialization, instead of runtime dynamic * type of the root object itself. *<p> * Note that method does NOT change state of this reader, but * rather construct and returns a newly configured instance. */ public ObjectWriter withType(JavaType rootType) { JsonSerializer<Object> rootSer = _prefetchRootSerializer(_config, rootType); return (rootType == _rootType) ? this // type is stored here, no need to make a copy of config : new ObjectWriter(this, _config, rootType, rootSer, _prettyPrinter, _schema); }
/** * Constructor used by {@link ObjectMapper} for initial instantiation */ protected ObjectWriter(ObjectMapper mapper, SerializationConfig config, JavaType rootType, PrettyPrinter pp) { _config = config; _serializerProvider = mapper._serializerProvider; _serializerFactory = mapper._serializerFactory; _generatorFactory = mapper._jsonFactory; _generatorSettings = (pp == null) ? GeneratorSettings.empty : new GeneratorSettings(pp, null, null, null); // 29-Apr-2014, tatu: There is no "untyped serializer", so: if (rootType == null || rootType.hasRawClass(Object.class)) { _prefetch = Prefetch.empty; } else { rootType = rootType.withStaticTyping(); _prefetch = _prefetchRootSerializer(config, rootType); } }
/** * Method that will construct a new instance that uses specific type * as the root type for serialization, instead of runtime dynamic * type of the root object itself. *<p> * Note that method does NOT change state of this reader, but * rather construct and returns a newly configured instance. * * @since 2.5 */ public ObjectWriter forType(JavaType rootType) { Prefetch pf; if (rootType == null || rootType.hasRawClass(Object.class)) { pf = Prefetch.empty; } else { // 15-Mar-2013, tatu: Important! Indicate that static typing is needed: rootType = rootType.withStaticTyping(); pf = _prefetchRootSerializer(_config, rootType); } return (pf == _prefetch) ? this : _new(_generatorSettings, pf); }
/** * Constructor used by {@link ObjectMapper} for initial instantiation */ protected ObjectWriter(ObjectMapper mapper, SerializationConfig config, JavaType rootType, PrettyPrinter pp) { _config = config; _serializerProvider = mapper._serializerProvider; _serializerFactory = mapper._serializerFactory; _generatorFactory = mapper._jsonFactory; _generatorSettings = (pp == null) ? GeneratorSettings.empty : new GeneratorSettings(pp, null, null, null); // 29-Apr-2014, tatu: There is no "untyped serializer", so: if (rootType == null || rootType.hasRawClass(Object.class)) { _prefetch = Prefetch.empty; } else { rootType = rootType.withStaticTyping(); _prefetch = _prefetchRootSerializer(config, rootType); } }
/** * Method that will construct a new instance that uses specific type * as the root type for serialization, instead of runtime dynamic * type of the root object itself. *<p> * Note that method does NOT change state of this reader, but * rather construct and returns a newly configured instance. * * @since 2.5 */ public ObjectWriter forType(JavaType rootType) { Prefetch pf; if (rootType == null || rootType.hasRawClass(Object.class)) { pf = Prefetch.empty; } else { // 15-Mar-2013, tatu: Important! Indicate that static typing is needed: rootType = rootType.withStaticTyping(); pf = _prefetchRootSerializer(_config, rootType); } return (pf == _prefetch) ? this : _new(_generatorSettings, pf); }