Skip to content

Commit

Permalink
Fix #1973
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 16, 2018
1 parent f350b20 commit 3181c25
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 52 deletions.
5 changes: 3 additions & 2 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Versions: 3.x (for earlier see VERSION-2.x)
#1916: Change `MapperFeature.USE_GETTERS_AS_SETTERS)` default to `false`
#1917: Remove `canSerialize` and `canDeserialize` methods from `ObjectMapper`
#1954: Add Builder pattern for creating configured `ObjectMapper` instances
- Remove `MappingJsonFactory`
#1955: Change the way `Module`s configure, interact with `ObjectMapper`

#1973: Remove support for "default [Map] key serializer" configuration from
`SerializerProvider`
- Remove `MappingJsonFactory`
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public abstract class SerializerProvider
protected final static JsonSerializer<Object> DEFAULT_UNKNOWN_SERIALIZER = new UnknownSerializer();

/*
/**********************************************************
/**********************************************************************
/* Configuration, general
/**********************************************************
/**********************************************************************
*/

/**
Expand Down Expand Up @@ -154,13 +154,6 @@ public abstract class SerializerProvider
*/
protected JsonSerializer<Object> _unknownTypeSerializer = DEFAULT_UNKNOWN_SERIALIZER;

/**
* Serializer used to output non-null keys of Maps (which will get
* output as JSON Objects), if not null; if null, us the standard
* default key serializer.
*/
protected JsonSerializer<Object> _defaulKeySerializer;

/**
* Serializer used to output a null value. Default implementation
* writes nulls using {@link JsonGenerator#writeNull}.
Expand Down Expand Up @@ -252,7 +245,6 @@ protected SerializerProvider(SerializerProvider src,

_serializerCache = src._serializerCache;
_unknownTypeSerializer = src._unknownTypeSerializer;
_defaulKeySerializer = src._defaulKeySerializer;
_nullValueSerializer = src._nullValueSerializer;
_nullKeySerializer = src._nullKeySerializer;

Expand Down Expand Up @@ -285,7 +277,6 @@ protected SerializerProvider(SerializerProvider src)
_serializerCache = new SerializerCache();

_unknownTypeSerializer = src._unknownTypeSerializer;
_defaulKeySerializer = src._defaulKeySerializer;
_nullValueSerializer = src._nullValueSerializer;
_nullKeySerializer = src._nullKeySerializer;

Expand Down Expand Up @@ -386,20 +377,6 @@ public void writeTree(JsonGenerator gen, TreeNode tree) throws IOException
/**********************************************************************
*/

/**
* Method that can be used to specify serializer that will be
* used to write JSON property names matching null keys for Java
* Maps (which will throw an exception if try write such property
* name)
*/
public void setDefaultKeySerializer(JsonSerializer<Object> ks)
{
if (ks == null) {
throw new IllegalArgumentException("Cannot pass null JsonSerializer");
}
_defaulKeySerializer = ks;
}

/**
* Method that can be used to specify serializer that will be
* used to write JSON values matching Java null values
Expand Down Expand Up @@ -886,8 +863,9 @@ public TypeSerializer findTypeSerializer(JavaType javaType) throws JsonMappingEx
public JsonSerializer<Object> findKeySerializer(JavaType keyType, BeanProperty property)
throws JsonMappingException
{
JsonSerializer<Object> ser = _serializerFactory.createKeySerializer(_config, keyType, _defaulKeySerializer);
// 25-Feb-2011, tatu: As per [JACKSON-519], need to ensure contextuality works here, too
// 16-Mar-2018, tatu: Used to have "default key serializer" in 2.x; dropped to let/make
// custom code use Module interface or similar to provide key serializers
JsonSerializer<Object> ser = _serializerFactory.createKeySerializer(_config, keyType, null);
return _handleContextualResolvable(ser, property);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public abstract class SerializerFactory
*
* @param prov Provider that needs to be used to resolve annotation-provided
* serializers (but NOT for others)
*
* @since 2.1 (earlier versions had method with different signature)
*/
public abstract JsonSerializer<Object> createSerializer(SerializerProvider prov,
JavaType baseType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public static JsonSerializer<Object> getStdKeySerializer(SerializationConfig con
/**
* Method called if no specified key serializer was located; will return a
* "default" key serializer.
*
* @since 2.7
*/
@SuppressWarnings("unchecked")
public static JsonSerializer<Object> getFallbackKeySerializer(SerializationConfig config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import com.fasterxml.jackson.core.Base64Variants;
import com.fasterxml.jackson.core.JsonGenerator;

import com.fasterxml.jackson.databind.*;

@SuppressWarnings("serial")
Expand Down Expand Up @@ -37,15 +38,6 @@ public String toString() {

static class WatMap extends HashMap<Wat,Boolean> { }

static class DefaultKeySerializer extends JsonSerializer<Object>
{
@Override
public void serialize(Object value, JsonGenerator g, SerializerProvider provider) throws IOException
{
g.writeFieldName("DEFAULT:"+value);
}
}

/*
/**********************************************************
/* Test methods
Expand Down Expand Up @@ -73,15 +65,6 @@ public void testClassKey() throws IOException
assertEquals(aposToQuotes("{'java.lang.String':2}"), json);
}

public void testDefaultKeySerializer() throws IOException
{
ObjectMapper m = new ObjectMapper();
m.getSerializerProvider().setDefaultKeySerializer(new DefaultKeySerializer());
Map<String,String> map = new HashMap<String,String>();
map.put("a", "b");
assertEquals("{\"DEFAULT:a\":\"b\"}", m.writeValueAsString(map));
}

// [databind#1552]
public void testMapsWithBinaryKeys() throws Exception
{
Expand Down

0 comments on commit 3181c25

Please sign in to comment.