Skip to content

Commit

Permalink
Another major refactoring: add SerializationContexts to cleave off …
Browse files Browse the repository at this point in the history
…"blueprint" part of `SerializerProvider`
  • Loading branch information
cowtowncoder committed Apr 20, 2018
1 parent ff16cea commit f89a309
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 232 deletions.
13 changes: 5 additions & 8 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,13 @@ protected Object readResolve() {
protected final SerializationConfig _serializationConfig;

/**
* Object that manages access to serializers used for serialization,
* including caching.
* It is configured with {@link #_serializerFactory} to allow
* for constructing custom serializers.
* Factory used for constructing per-call {@link SerializerProvider}s.
*<p>
* Note: while serializers are only exposed {@link SerializerProvider},
* mappers and readers need to access additional API defined by
* {@link DefaultSerializerProvider}
*/
protected final DefaultSerializerProvider _serializerProvider;
protected final SerializationContexts _serializationContexts;

/**
* Serializer factory used for constructing serializers.
Expand Down Expand Up @@ -363,7 +360,7 @@ protected ObjectMapper(MapperBuilder<?,?> builder)
_subtypeResolver = builder.subtypeResolver();

// Ser/deser framework factories
_serializerProvider = builder.serializerProvider();
_serializationContexts = builder.serializationContexts();
_serializerFactory = builder.serializerFactory();

_deserializationContext = builder.deserializationContext();
Expand Down Expand Up @@ -2354,13 +2351,13 @@ public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visi
*/
protected DefaultSerializerProvider _serializerProvider(SerializationConfig config) {
// 03-Oct-2017, tatu: Should be ok to pass "empty" generator settings...
return _serializerProvider.createInstance(config,
return _serializationContexts.createContext(config,
GeneratorSettings.empty(), _serializerFactory);
}

protected DefaultSerializerProvider _serializerProvider() {
// 03-Oct-2017, tatu: Should be ok to pass "empty" generator settings...
return _serializerProvider.createInstance(serializationConfig(),
return _serializationContexts.createContext(serializationConfig(),
GeneratorSettings.empty(), _serializerFactory);
}

Expand Down
104 changes: 55 additions & 49 deletions src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.fasterxml.jackson.core.util.*;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.fasterxml.jackson.databind.cfg.GeneratorSettings;
import com.fasterxml.jackson.databind.cfg.SerializationContexts;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ArrayNode;
Expand All @@ -36,17 +37,24 @@ public class ObjectWriter
private static final long serialVersionUID = 1;

/*
/**********************************************************
/**********************************************************************
/* Immutable configuration from ObjectMapper
/**********************************************************
/**********************************************************************
*/

/**
* General serialization configuration settings
*/
protected final SerializationConfig _config;

protected final DefaultSerializerProvider _serializerProvider;
/**
* Factory used for constructing per-call {@link SerializerProvider}s.
*<p>
* Note: while serializers are only exposed {@link SerializerProvider},
* mappers and readers need to access additional API defined by
* {@link DefaultSerializerProvider}
*/
protected final SerializationContexts _serializationContexts;

protected final SerializerFactory _serializerFactory;

Expand All @@ -56,9 +64,9 @@ public class ObjectWriter
protected final TokenStreamFactory _generatorFactory;

/*
/**********************************************************
/**********************************************************************
/* Configuration that can be changed via mutant factories
/**********************************************************
/**********************************************************************
*/

/**
Expand All @@ -76,9 +84,9 @@ public class ObjectWriter
protected final Prefetch _prefetch;

/*
/**********************************************************
/**********************************************************************
/* Life-cycle, constructors
/**********************************************************
/**********************************************************************
*/

/**
Expand All @@ -88,7 +96,7 @@ protected ObjectWriter(ObjectMapper mapper, SerializationConfig config,
JavaType rootType, PrettyPrinter pp)
{
_config = config;
_serializerProvider = mapper._serializerProvider;
_serializationContexts = mapper._serializationContexts;
_serializerFactory = mapper._serializerFactory;
_generatorFactory = mapper._streamFactory;
_generatorSettings = (pp == null) ? GeneratorSettings.empty
Expand All @@ -109,7 +117,7 @@ protected ObjectWriter(ObjectMapper mapper, SerializationConfig config,
protected ObjectWriter(ObjectMapper mapper, SerializationConfig config)
{
_config = config;
_serializerProvider = mapper._serializerProvider;
_serializationContexts = mapper._serializationContexts;
_serializerFactory = mapper._serializerFactory;
_generatorFactory = mapper._streamFactory;

Expand All @@ -125,7 +133,7 @@ protected ObjectWriter(ObjectMapper mapper, SerializationConfig config,
{
_config = config;

_serializerProvider = mapper._serializerProvider;
_serializationContexts = mapper._serializationContexts;
_serializerFactory = mapper._serializerFactory;
_generatorFactory = mapper._streamFactory;

Expand All @@ -142,7 +150,7 @@ protected ObjectWriter(ObjectWriter base, SerializationConfig config,
{
_config = config;

_serializerProvider = base._serializerProvider;
_serializationContexts = base._serializationContexts;
_serializerFactory = base._serializerFactory;
_generatorFactory = base._generatorFactory;

Expand All @@ -157,7 +165,7 @@ protected ObjectWriter(ObjectWriter base, SerializationConfig config)
{
_config = config;

_serializerProvider = base._serializerProvider;
_serializationContexts = base._serializationContexts;
_serializerFactory = base._serializerFactory;
_generatorFactory = base._generatorFactory;

Expand All @@ -175,10 +183,9 @@ public Version version() {
}

/*
/**********************************************************
/* Methods sub-classes MUST override, used for constructing
/* writer instances, (re)configuring parser instances.
/**********************************************************
/**********************************************************************
/* Helper methdos to simplify mutant-factory implementation
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -217,9 +224,9 @@ protected final SequenceWriter _newSequenceWriter(DefaultSerializerProvider prov
}

/*
/**********************************************************
/**********************************************************************
/* Life-cycle, fluent factories for SerializationFeature
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -271,9 +278,9 @@ public ObjectWriter withoutFeatures(SerializationFeature... features) {
}

/*
/**********************************************************
/**********************************************************************
/* Life-cycle, fluent factories for JsonGenerator.Feature
/**********************************************************
/**********************************************************************
*/

public ObjectWriter with(JsonGenerator.Feature feature) {
Expand All @@ -293,9 +300,9 @@ public ObjectWriter withoutFeatures(JsonGenerator.Feature... features) {
}

/*
/**********************************************************
/**********************************************************************
/* Life-cycle, fluent factories for FormatFeature
/**********************************************************
/**********************************************************************
*/

public ObjectWriter with(FormatFeature feature) {
Expand All @@ -315,9 +322,9 @@ public ObjectWriter withoutFeatures(FormatFeature... features) {
}

/*
/**********************************************************
/**********************************************************************
/* Life-cycle, fluent factories, type-related
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -354,9 +361,9 @@ public ObjectWriter forType(TypeReference<?> rootType) {
}

/*
/**********************************************************
/**********************************************************************
/* Life-cycle, fluent factories, other
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -502,10 +509,9 @@ public ObjectWriter withRootValueSeparator(SerializableString sep) {
}

/*
/**********************************************************
/* Public API: constructing Generator that are properly linked
/* to `ObjectWriteContext`
/**********************************************************
/**********************************************************************
/* Public API: constructing Generator that are properly linked to `ObjectWriteContext`
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -570,9 +576,9 @@ public JsonGenerator createGenerator(DataOutput out) throws IOException {
}

/*
/**********************************************************
/**********************************************************************
/* Convenience methods for JsonNode creation
/**********************************************************
/**********************************************************************
*/

public ObjectNode createObjectNode() {
Expand All @@ -584,9 +590,9 @@ public ArrayNode createArrayNode() {
}

/*
/**********************************************************
/**********************************************************************
/* Factory methods for sequence writers
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -745,9 +751,9 @@ public SequenceWriter writeValuesAsArray(DataOutput out) throws IOException {
}

/*
/**********************************************************
/**********************************************************************
/* Simple accessors
/**********************************************************
/**********************************************************************
*/

public boolean isEnabled(SerializationFeature f) {
Expand Down Expand Up @@ -802,9 +808,9 @@ public TypeFactory getTypeFactory() {
}

/*
/**********************************************************
/**********************************************************************
/* Serialization methods; ones from ObjectCodec first
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -836,9 +842,9 @@ public void writeValue(JsonGenerator gen, Object value) throws IOException
}

/*
/**********************************************************
/**********************************************************************
/* Serialization methods, others
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -987,9 +993,9 @@ private final void _writeCloseable(JsonGenerator gen, Object value)
}

/*
/**********************************************************
/**********************************************************************
/* Other public methods
/**********************************************************
/**********************************************************************
*/

/**
Expand All @@ -1015,24 +1021,24 @@ public void acceptJsonFormatVisitor(Class<?> rawType, JsonFormatVisitorWrapper v
}

/*
/**********************************************************
/**********************************************************************
/* Overridable helper methods
/**********************************************************
/**********************************************************************
*/

/**
* Overridable helper method used for constructing
* {@link SerializerProvider} to use for serialization.
*/
protected final DefaultSerializerProvider _serializerProvider() {
return _serializerProvider.createInstance(_config, _generatorSettings,
return _serializationContexts.createContext(_config, _generatorSettings,
_serializerFactory);
}

/*
/**********************************************************
/**********************************************************************
/* Internal methods
/**********************************************************
/**********************************************************************
*/

protected void _verifySchemaType(FormatSchema schema)
Expand All @@ -1046,9 +1052,9 @@ protected void _verifySchemaType(FormatSchema schema)
}

/*
/**********************************************************
/**********************************************************************
/* Helper classes for configuration
/**********************************************************
/**********************************************************************
*/

/**
Expand Down
Loading

0 comments on commit f89a309

Please sign in to comment.