Skip to content

Commit 52ea58b

Browse files
authored
Fix #4570: deprecate ObjectMapper.canDeserialize()/canSerialize() (#4571)
1 parent 894e23a commit 52ea58b

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Project: jackson-databind
4343
#4545: Unexpected deserialization behavior with `@JsonCreator`,
4444
`@JsonProperty` and javac `-parameters`
4545
(reported by Alexandre J)
46+
#4570: Deprecate `ObjectMapper.canDeserialize()`/`ObjectMapper.canSerialize()`
4647
4748
2.17.2 (not yet released)
4849

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,10 @@ public <T extends JsonNode> T valueToTree(Object fromValue)
36363636
* @return True if mapper can find a serializer for instances of
36373637
* given class (potentially serializable), false otherwise (not
36383638
* serializable)
3639+
*
3640+
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
36393641
*/
3642+
@Deprecated // @since 2.18
36403643
public boolean canSerialize(Class<?> type) {
36413644
return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, null);
36423645
}
@@ -3647,7 +3650,10 @@ public boolean canSerialize(Class<?> type) {
36473650
* serializer: this may be useful in figuring out what the actual problem is.
36483651
*
36493652
* @since 2.3
3653+
*
3654+
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
36503655
*/
3656+
@Deprecated // @since 2.18
36513657
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
36523658
return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, cause);
36533659
}
@@ -3668,7 +3674,10 @@ public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
36683674
* @return True if mapper can find a serializer for instances of
36693675
* given class (potentially serializable), false otherwise (not
36703676
* serializable)
3677+
*
3678+
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
36713679
*/
3680+
@Deprecated // @since 2.18
36723681
public boolean canDeserialize(JavaType type)
36733682
{
36743683
return createDeserializationContext(null,
@@ -3681,7 +3690,10 @@ public boolean canDeserialize(JavaType type)
36813690
* serializer: this may be useful in figuring out what the actual problem is.
36823691
*
36833692
* @since 2.3
3693+
*
3694+
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
36843695
*/
3696+
@Deprecated // @since 2.18
36853697
public boolean canDeserialize(JavaType type, AtomicReference<Throwable> cause)
36863698
{
36873699
return createDeserializationContext(null,
@@ -3690,8 +3702,7 @@ public boolean canDeserialize(JavaType type, AtomicReference<Throwable> cause)
36903702

36913703
/*
36923704
/**********************************************************
3693-
/* Extended Public API, deserialization,
3694-
/* convenience methods
3705+
/* Extended Public API, deserialization, convenience methods
36953706
/**********************************************************
36963707
*/
36973708

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

+10
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,13 @@ public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visi
12101210
acceptJsonFormatVisitor(_config.constructType(type), visitor);
12111211
}
12121212

1213+
/**
1214+
* Method that can be called to check whether {@code ObjectWriter} thinks
1215+
* it could serialize an instance of given Class.
1216+
*
1217+
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
1218+
*/
1219+
@Deprecated // @since 2.18
12131220
public boolean canSerialize(Class<?> type) {
12141221
_assertNotNull("type", type);
12151222
return _serializerProvider().hasSerializerFor(type, null);
@@ -1220,7 +1227,10 @@ public boolean canSerialize(Class<?> type) {
12201227
* and optionally why (as per {@link Throwable} returned).
12211228
*
12221229
* @since 2.3
1230+
*
1231+
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
12231232
*/
1233+
@Deprecated // @since 2.18
12241234
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
12251235
_assertNotNull("type", type);
12261236
return _serializerProvider().hasSerializerFor(type, cause);

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

+3
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ public void testCustomDefaultPrettyPrinter() throws Exception
401401
}
402402

403403
// For [databind#703], [databind#978]
404+
@SuppressWarnings("deprecation")
404405
@Test
405406
public void testNonSerializabilityOfObject()
406407
{
@@ -420,6 +421,7 @@ public void testNonSerializabilityOfObject()
420421
}
421422

422423
// for [databind#756]
424+
@SuppressWarnings("deprecation")
423425
@Test
424426
public void testEmptyBeanSerializability()
425427
{
@@ -432,6 +434,7 @@ public void testEmptyBeanSerializability()
432434
}
433435

434436
// for [databind#2749]: just to check there's no NPE; method really not useful
437+
@SuppressWarnings("deprecation")
435438
@Test
436439
public void testCanDeserialize()
437440
{

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

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public void testPolymorphicWithTyping() throws Exception
132132
assertEquals(a2q("{'type':'B','b':-5}"), json);
133133
}
134134

135+
@SuppressWarnings("deprecation")
135136
@Test
136137
public void testCanSerialize() throws Exception
137138
{

0 commit comments

Comments
 (0)