diff options
author | Tatu Saloranta <tsaloranta@gmail.com> | 2011-12-23 00:31:35 -0800 |
---|---|---|
committer | Tatu Saloranta <tsaloranta@gmail.com> | 2011-12-23 00:31:35 -0800 |
commit | e4f23bb6779d434d88a7c4335f92d13ea639b373 (patch) | |
tree | a4e006fe2749c79bf4a7637451e9a9dedb05890e /src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java | |
parent | 90c4352c4d2412fbe4be10e93e2c520b9658a752 (diff) | |
download | jackson-databind-e4f23bb6779d434d88a7c4335f92d13ea639b373.tar.gz |
First check-in, tons of compilation errors to resolve
Diffstat (limited to 'src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java')
-rw-r--r-- | src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java new file mode 100644 index 000000000..933aed8c5 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializer.java @@ -0,0 +1,127 @@ +package com.fasterxml.jackson.databind.ser; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.type.JavaType; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanSerializer; +import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; + + +/** + * Serializer class that can serialize arbitrary bean objects + *<p> + * Implementation note: we will post-process resulting serializer, + * to figure out actual serializers for final types. This must be + * done from {@link #resolve} method, and NOT from constructor; + * otherwise we could end up with an infinite loop. + *<p> + * Since 1.7 instances are immutable; this is achieved by using a + * separate builder during construction process. + */ +public class BeanSerializer + extends BeanSerializerBase +{ + /* + /********************************************************** + /* Life-cycle: constructors + /********************************************************** + */ + + /** + * @param type Nominal type of values handled by this serializer + * @param properties Property writers used for actual serialization + */ + public BeanSerializer(JavaType type, + BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties, + AnyGetterWriter anyGetterWriter, + Object filterId) + { + super(type, properties, filteredProperties, anyGetterWriter, filterId); + } + + public BeanSerializer(Class<?> rawType, + BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties, + AnyGetterWriter anyGetterWriter, + Object filterId) + { + super(rawType, properties, filteredProperties, anyGetterWriter, filterId); + } + + /** + * Copy-constructor that is useful for sub-classes that just want to + * copy all super-class properties without modifications. + * + * @since 1.7 + */ + protected BeanSerializer(BeanSerializer src) { + super(src); + } + + /** + * Alternate copy constructor that can be used to construct + * standard {@link BeanSerializer} passing an instance of + * "compatible enough" source serializer. + * + * @since 1.9 + */ + protected BeanSerializer(BeanSerializerBase src) { + super(src); + } + + /* + /********************************************************** + /* Life-cycle: factory methods, fluent factories + /********************************************************** + */ + + /** + * Method for constructing dummy bean deserializer; one that + * never outputs any properties + */ + public static BeanSerializer createDummy(Class<?> forType) + { + return new BeanSerializer(forType, NO_PROPS, null, null, null); + } + + @Override + public JsonSerializer<Object> unwrappingSerializer() { + return new UnwrappingBeanSerializer(this); + } + + /* + /********************************************************** + /* JsonSerializer implementation that differs between impls + /********************************************************** + */ + + /** + * Main serialization method that will delegate actual output to + * configured + * {@link BeanPropertyWriter} instances. + */ + @Override + public final void serialize(Object bean, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonGenerationException + { + jgen.writeStartObject(); + if (_propertyFilterId != null) { + serializeFieldsFiltered(bean, jgen, provider); + } else { + serializeFields(bean, jgen, provider); + } + jgen.writeEndObject(); + } + + /* + /********************************************************** + /* Standard methods + /********************************************************** + */ + + @Override public String toString() { + return "BeanSerializer for "+handledType().getName(); + } +} |