Skip to content

Commit 2ec3ad2

Browse files
committed
1 parent 06da5d4 commit 2ec3ad2

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Project: jackson-databind
1414
(reported by Miles K)
1515
#497: Add new JsonInclude.Include feature to exclude maps after exclusion removes all elements
1616
#819: Add support for setting `FormatFeature` via `ObjectReader`, `ObjectWriter`
17+
#898: Add `ObjectMapper.getSerializerProviderInstance()`
1718
#915: ObjectMapper default timezone is GMT, should be UTC
1819
(suggested by Infrag@github)
1920
#918: Add `MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING`

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,18 +1030,38 @@ public SerializerFactory getSerializerFactory() {
10301030
}
10311031

10321032
/**
1033-
* Method for setting specific {@link SerializerProvider} to use
1034-
* for handling caching of {@link JsonSerializer} instances.
1033+
* Method for setting "blueprint" {@link SerializerProvider} instance
1034+
* to use as the base for actual provider instances to use for handling
1035+
* caching of {@link JsonSerializer} instances.
10351036
*/
10361037
public ObjectMapper setSerializerProvider(DefaultSerializerProvider p) {
10371038
_serializerProvider = p;
10381039
return this;
10391040
}
10401041

1042+
/**
1043+
* Accessor for the "blueprint" (or, factory) instance, from which instances
1044+
* are created by calling {@link DefaultSerializerProvider#createInstance}.
1045+
* Note that returned instance can not be directly used as it is not properly
1046+
* configured: to get a properly configured instance to call, use
1047+
* {@link #getSerializerProviderInstance()} instead.
1048+
*/
10411049
public SerializerProvider getSerializerProvider() {
10421050
return _serializerProvider;
10431051
}
10441052

1053+
/**
1054+
* Accessor for constructing and returning a {@link SerializerProvider}
1055+
* instance that may be used for accessing serializers. This is same as
1056+
* calling {@link #getSerializerProvider}, and calling <code>createInstance</code>
1057+
* on it.
1058+
*
1059+
* @since 2.7
1060+
*/
1061+
public SerializerProvider getSerializerProviderInstance() {
1062+
return _serializerProvider(_serializationConfig);
1063+
}
1064+
10451065
/*
10461066
/**********************************************************
10471067
/* Configuration: mix-in annotations
@@ -3429,7 +3449,7 @@ public <T> T convertValue(Object fromValue, JavaType toValueType)
34293449
protected Object _convert(Object fromValue, JavaType toValueType)
34303450
throws IllegalArgumentException
34313451
{
3432-
// also, as per [Issue-11], consider case for simple cast
3452+
// also, as per [databind#11], consider case for simple cast
34333453
/* But with caveats: one is that while everything is Object.class, we don't
34343454
* want to "optimize" that out; and the other is that we also do not want
34353455
* to lose conversions of generic types.

src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected SerializerProvider(SerializerProvider src,
235235
/**
236236
* Copy-constructor used when making a copy of a blueprint instance.
237237
*
238-
* @since 2.5.0
238+
* @since 2.5
239239
*/
240240
protected SerializerProvider(SerializerProvider src)
241241
{

src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import java.util.*;
55

66
import com.fasterxml.jackson.core.*;
7+
78
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
89

9-
import com.fasterxml.jackson.databind.ObjectMapper;
1010
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
1111
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
1212
import com.fasterxml.jackson.databind.node.*;
@@ -255,12 +255,21 @@ public void testNonSerializabilityOfObject()
255255
public void testEmptyBeanSerializability()
256256
{
257257
// with default settings, error
258-
/*
259258
assertFalse(MAPPER.writer().with(SerializationFeature.FAIL_ON_EMPTY_BEANS)
260259
.canSerialize(EmptyBean.class));
261-
*/
262260
// but with changes
263261
assertTrue(MAPPER.writer().without(SerializationFeature.FAIL_ON_EMPTY_BEANS)
264262
.canSerialize(EmptyBean.class));
265263
}
264+
265+
// for [databind#898]
266+
public void testSerializerProviderAccess() throws Exception
267+
{
268+
// ensure we have "fresh" instance, just in case
269+
ObjectMapper mapper = new ObjectMapper();
270+
JsonSerializer<?> ser = mapper.getSerializerProviderInstance()
271+
.findValueSerializer(Bean.class);
272+
assertNotNull(ser);
273+
assertEquals(Bean.class, ser.handledType());
274+
}
266275
}

0 commit comments

Comments
 (0)