Skip to content

Commit 0b04883

Browse files
committed
Add release notes for #3103, minor tweaks over #3608
1 parent 53f5dda commit 0b04883

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

release-notes/CREDITS-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,8 @@ Igor Shymko (ancane@github)
14851485
(2.14.0)
14861486
14871487
Jordi Ortolá Ankum (Tomasito665@github)
1488+
* Contributed #3013: Allow disabling Integer to String coercion via `CoercionConfig`
1489+
(2.14.0)
14881490
* Contributed #3503: `StdDeserializer` coerces ints to floats even if configured to fail
14891491
(2.14.0)
14901492

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Project: jackson-databind
1111
#2541: Cannot merge polymorphic objects
1212
(reported by Matthew A)
1313
(fix contributed by James W)
14+
#3013: Allow disabling Integer to String coercion via `CoercionConfig`
15+
(reported by @emilkostadinov)
16+
(fix contributed by Jordi O-A)
1417
#3311: Add serializer-cache size limit to avoid Metaspace issues from
1518
caching Serializers
1619
(requested by mcolemanNOW@github)

src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,35 @@ protected java.util.Date _parseDate(String value, DeserializationContext ctxt)
13661366
}
13671367

13681368
/**
1369-
* Helper method used for accessing String value, if possible, doing
1369+
* @since 2.1
1370+
* @deprecated Since 2.14 (use the non-deprecated overload)
1371+
*/
1372+
@Deprecated
1373+
protected final String _parseString(JsonParser p, DeserializationContext ctxt)
1374+
throws IOException
1375+
{
1376+
return _parseString(p, ctxt,
1377+
// Note: could consider passing `this`, but since this methods is
1378+
// often called for values "inside" type we are handling (like
1379+
// String array or Collection of Strings) that would probably
1380+
// not match. So default to "nulls as nulls" handler.
1381+
NullsConstantProvider.nuller());
1382+
}
1383+
1384+
/**
1385+
* Helper method used for deserializing String value, if possible, doing
13701386
* necessary conversion or throwing exception as necessary.
1387+
*<p>
1388+
* Starting with 2.14 will also start checking {@code CoercionConfig}
1389+
* configuration to check whether coercion needed is allowed.
13711390
*
1372-
* @since 2.1
1391+
* @param p Currently active parser being iterated over
1392+
* @param ctxt Deserialization context
1393+
* @param nullProvider Entity we (only) need for case of secondary value
1394+
* type being coerced into {@code null}: if so, provider is asked for
1395+
* possible "null replacement" value.
1396+
*
1397+
* @since 2.14 (with this signature)
13731398
*/
13741399
protected final String _parseString(JsonParser p, DeserializationContext ctxt,
13751400
NullValueProvider nullProvider)
@@ -1413,7 +1438,7 @@ protected final String _parseString(JsonParser p, DeserializationContext ctxt,
14131438
return text;
14141439
}
14151440
}
1416-
return (String) ctxt.handleUnexpectedToken(String.class, p);
1441+
return (String) ctxt.handleUnexpectedToken(getValueType(ctxt), p);
14171442
}
14181443

14191444
/**

src/main/java/com/fasterxml/jackson/databind/deser/std/StringArrayDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class StringArrayDeserializer
4444
protected JsonDeserializer<String> _elementDeserializer;
4545

4646
/**
47-
* Handler we need for dealing with nulls.
47+
* Handler we need for dealing with null values as elements
4848
*
4949
* @since 2.9
5050
*/

src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.core.*;
66
import com.fasterxml.jackson.databind.*;
77
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
8-
import com.fasterxml.jackson.databind.cfg.CoercionAction;
98
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
109
import com.fasterxml.jackson.databind.type.LogicalType;
1110

@@ -38,6 +37,7 @@ public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingExcep
3837
@Override
3938
public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
4039
{
40+
// The critical path: ensure we handle the common case first.
4141
if (p.hasToken(JsonToken.VALUE_STRING)) {
4242
return p.getText();
4343
}

src/test/java/com/fasterxml/jackson/databind/convert/CoerceIntToStringTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
1010
import com.fasterxml.jackson.databind.type.LogicalType;
1111

12+
// [databind#3013] / PR #3608
1213
public class CoerceIntToStringTest extends BaseMapTest
1314
{
1415
private final ObjectMapper DEFAULT_MAPPER = newJsonMapper();

0 commit comments

Comments
 (0)