Skip to content

Commit 7ff745c

Browse files
committed
More complete fix for #735
1 parent de5642e commit 7ff745c

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

release-notes/VERSION

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.4.6 (not yet released)
8+
9+
#735: (complete fix) @JsonDeserialize on Map with contentUsing custom deserializer overwrites default behavior
10+
(reported by blackfyre512@github) (regression due to #604)
11+
712
2.4.5.1 (26-Mar-2015)
813

914
Special one-off "micro patch" for:
1015

1116
#706: Add support for `@JsonUnwrapped` via JSON Schema module
1217
#707: Error in getting string representation of an ObjectNode with a float number value
1318
(reported by @navidqar)
14-
#735: @JsonDeserialize on Map with contentUsing custom deserializer overwrites default behavior
15-
(reported by blackfyre512@github) (regression due to #604)
19+
#735: (partial) @JsonDeserialize on Map with contentUsing custom deserializer overwrites default behavior
1620

1721
2.4.5 (13-Jan-2015)
1822

src/main/java/com/fasterxml/jackson/databind/deser/DeserializerCache.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ protected JsonDeserializer<Object> _findCachedDeserializer(JavaType type)
204204
if (type == null) {
205205
throw new IllegalArgumentException("Null JavaType passed");
206206
}
207+
if (_hasCustomValueHandler(type)) {
208+
return null;
209+
}
207210
return _cachedDeserializers.get(type);
208211
}
209212

@@ -214,7 +217,7 @@ protected JsonDeserializer<Object> _findCachedDeserializer(JavaType type)
214217
* @param ctxt Currently active deserialization context
215218
* @param type Type of property to deserialize
216219
*/
217-
protected JsonDeserializer<Object>_createAndCacheValueDeserializer(DeserializationContext ctxt,
220+
protected JsonDeserializer<Object> _createAndCacheValueDeserializer(DeserializationContext ctxt,
218221
DeserializerFactory factory, JavaType type)
219222
throws JsonMappingException
220223
{
@@ -273,7 +276,8 @@ protected JsonDeserializer<Object> _createAndCache2(DeserializationContext ctxt,
273276
*/
274277
// 08-Jun-2010, tatu: Related to [JACKSON-296], need to avoid caching MapSerializers... so:
275278
boolean isResolvable = (deser instanceof ResolvableDeserializer);
276-
boolean addToCache = deser.isCachable();
279+
// 27-Mar-2015, tatu: As per [databind#735], avoid caching types with custom value desers
280+
boolean addToCache = !_hasCustomValueHandler(type) && deser.isCachable();
277281

278282
/* we will temporarily hold on to all created deserializers (to
279283
* handle cyclic references, and possibly reuse non-cached
@@ -538,6 +542,26 @@ private JavaType modifyTypeByAnnotation(DeserializationContext ctxt,
538542
return type;
539543
}
540544

545+
/*
546+
/**********************************************************
547+
/* Helper methods, other
548+
/**********************************************************
549+
*/
550+
551+
/**
552+
* Helper method used to prevent both caching and cache lookups for structured
553+
* types that have custom value handlers
554+
*
555+
* @since 2.4.6
556+
*/
557+
private boolean _hasCustomValueHandler(JavaType t) {
558+
if (t.isContainerType()) {
559+
JavaType ct = t.getContentType();
560+
return (ct != null) && (ct.getValueHandler() != null);
561+
}
562+
return false;
563+
}
564+
541565
private Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
542566
{
543567
if (src == null) {
@@ -552,7 +576,7 @@ private Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClas
552576
}
553577
return cls;
554578
}
555-
579+
556580
/*
557581
/**********************************************************
558582
/* Overridable error reporting methods

src/main/java/com/fasterxml/jackson/databind/node/FloatNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.math.BigInteger;
66

77
import com.fasterxml.jackson.core.*;
8-
import com.fasterxml.jackson.core.io.NumberOutput;
98
import com.fasterxml.jackson.databind.SerializerProvider;
109

1110
/**

src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.fasterxml.jackson.databind.deser;
22

33
import java.io.*;
4-
import java.lang.annotation.ElementType;
5-
import java.lang.annotation.Retention;
6-
import java.lang.annotation.RetentionPolicy;
7-
import java.lang.annotation.Target;
4+
import java.lang.annotation.*;
85
import java.util.*;
96

107
import com.fasterxml.jackson.annotation.JsonCreator;
118
import com.fasterxml.jackson.annotation.JsonProperty;
9+
1210
import com.fasterxml.jackson.core.*;
13-
import com.fasterxml.jackson.core.type.TypeReference;
11+
1412
import com.fasterxml.jackson.databind.*;
1513
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1614
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

src/test/java/com/fasterxml/jackson/databind/deser/TestForwardReference.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package com.fasterxml.jackson.databind.deser;
22

3-
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
4-
import com.fasterxml.jackson.annotation.JsonInclude;
5-
import com.fasterxml.jackson.annotation.JsonProperty;
6-
import com.fasterxml.jackson.annotation.JsonSubTypes;
7-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
8-
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
9-
import com.fasterxml.jackson.core.JsonParseException;
3+
import com.fasterxml.jackson.annotation.*;
4+
105
import com.fasterxml.jackson.databind.BaseMapTest;
116
import com.fasterxml.jackson.databind.DeserializationFeature;
127
import com.fasterxml.jackson.databind.ObjectMapper;
138
import com.fasterxml.jackson.databind.SerializationFeature;
149

1510
import java.io.IOException;
16-
import java.util.ArrayList;
17-
import java.util.List;
1811

1912
/**
2013
* Test for testing forward reference handling
@@ -67,7 +60,7 @@ public void setId(String id) {
6760
}
6861

6962
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
70-
private static class YetAnotherClass
63+
static class YetAnotherClass
7164
{
7265
public YetAnotherClass() {}
7366
public ForwardReferenceClass frc;

0 commit comments

Comments
 (0)