Skip to content

Commit fb96109

Browse files
committed
trying to streamline new test
1 parent 0ed838c commit fb96109

File tree

5 files changed

+40
-65
lines changed

5 files changed

+40
-65
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ public static List<Module> findModules(ClassLoader classLoader)
968968
public ObjectMapper findAndRegisterModules() {
969969
return registerModules(findModules());
970970
}
971-
971+
972972
/*
973973
/**********************************************************
974974
/* Configuration: main config object access

src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,23 +266,23 @@ public boolean hasPropertyBasedCreator() {
266266
/**********************************************************
267267
*/
268268

269-
private JavaType _computeDelegateType(AnnotatedWithParams creator, SettableBeanProperty[] delegateArgs)
269+
private JavaType _computeDelegateType(AnnotatedWithParams creator,
270+
SettableBeanProperty[] delegateArgs)
270271
{
271272
if (!_hasNonDefaultCreator || (creator == null)) {
272273
return null;
273-
} else {
274-
// need to find type...
275-
int ix = 0;
276-
if (delegateArgs != null) {
277-
for (int i = 0, len = delegateArgs.length; i < len; ++i) {
278-
if (delegateArgs[i] == null) { // marker for delegate itself
279-
ix = i;
280-
break;
281-
}
274+
}
275+
// need to find type...
276+
int ix = 0;
277+
if (delegateArgs != null) {
278+
for (int i = 0, len = delegateArgs.length; i < len; ++i) {
279+
if (delegateArgs[i] == null) { // marker for delegate itself
280+
ix = i;
281+
break;
282282
}
283283
}
284-
return creator.getParameterType(ix);
285284
}
285+
return creator.getParameterType(ix);
286286
}
287287

288288
private <T extends AnnotatedMember> T _fixAccess(T member)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
234234
kd = ((ContextualKeyDeserializer) kd).createContextual(ctxt, property);
235235
}
236236
}
237+
237238
JsonDeserializer<?> vd = _valueDeserializer;
238-
// #125: May have a content converter
239+
// [databind#125]: May have a content converter
239240
if (property != null) {
240241
vd = findConvertingContentDeserializer(ctxt, property, vd);
241242
}
@@ -329,7 +330,7 @@ public Map<Object,Object> deserialize(JsonParser p, DeserializationContext ctxt)
329330
// Ok: must point to START_OBJECT, FIELD_NAME or END_OBJECT
330331
JsonToken t = p.getCurrentToken();
331332
if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME && t != JsonToken.END_OBJECT) {
332-
// [JACKSON-620] (empty) String may be ok however:
333+
// (empty) String may be ok however:
333334
if (t == JsonToken.VALUE_STRING) {
334335
return (Map<Object,Object>) _valueInstantiator.createFromString(ctxt, p.getText());
335336
}
@@ -398,7 +399,7 @@ protected final void _readAndBind(JsonParser p, DeserializationContext ctxt,
398399
final KeyDeserializer keyDes = _keyDeserializer;
399400
final JsonDeserializer<Object> valueDes = _valueDeserializer;
400401
final TypeDeserializer typeDeser = _valueTypeDeserializer;
401-
402+
402403
MapReferringAccumulator referringAccumulator = null;
403404
boolean useObjectId = valueDes.getObjectIdReader() != null;
404405
if (useObjectId) {
@@ -465,7 +466,7 @@ protected final void _readAndBindStringMap(JsonParser p, DeserializationContext
465466
if (useObjectId) {
466467
referringAccumulator = new MapReferringAccumulator(_mapType.getContentType().getRawClass(), result);
467468
}
468-
469+
469470
String key;
470471
if (p.isExpectedStartObjectToken()) {
471472
key = p.nextFieldName();

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public final class AnnotatedClass
123123
* or have at least one annotation.
124124
*/
125125
protected List<AnnotatedField> _fields;
126-
126+
127127
/*
128128
/**********************************************************
129129
/* Life-cycle
@@ -427,8 +427,12 @@ private void resolveCreators()
427427
// Then see which constructors we have
428428
List<AnnotatedConstructor> constructors = null;
429429
ClassUtil.Ctor[] declaredCtors = ClassUtil.getConstructors(_class);
430-
// Constructor also always members of this class, so
431-
TypeResolutionContext typeContext = this;
430+
// Constructor also always members of this class
431+
TypeResolutionContext typeContext = this;
432+
433+
// 30-Apr-2016, tatu: [databind#1215]: Actually, while true, this does
434+
// NOT apply to context since sub-class may have type bindings
435+
// TypeResolutionContext typeContext = new TypeResolutionContext.Basic(_typeFactory, _type.getBindings());
432436
for (ClassUtil.Ctor ctor : declaredCtors) {
433437
if (_isIncludableConstructor(ctor.getConstructor())) {
434438
if (ctor.getParamCount() == 0) {
@@ -524,9 +528,9 @@ private void resolveMemberMethods()
524528
// and then augment these with annotations from super-types:
525529
for (JavaType type : _superTypes) {
526530
Class<?> mixin = (_mixInResolver == null) ? null : _mixInResolver.findMixInClassFor(type.getRawClass());
527-
TypeResolutionContext typeContext = new TypeResolutionContext.Basic(_typeFactory,
528-
type.getBindings());
529-
_addMemberMethods(type.getRawClass(), typeContext, _memberMethods, mixin, mixins);
531+
_addMemberMethods(type.getRawClass(),
532+
new TypeResolutionContext.Basic(_typeFactory, type.getBindings()),
533+
_memberMethods, mixin, mixins);
530534
}
531535
// Special case: mix-ins for Object.class? (to apply to ALL classes)
532536
if (_mixInResolver != null) {
@@ -539,7 +543,7 @@ private void resolveMemberMethods()
539543
/* Any unmatched mix-ins? Most likely error cases (not matching
540544
* any method); but there is one possible real use case:
541545
* exposing Object#hashCode (alas, Object#getClass can NOT be
542-
* exposed, see [JACKSON-140])
546+
* exposed)
543547
*/
544548
// 14-Feb-2011, tatu: AnnotationIntrospector is null if annotations not enabled; if so, can skip:
545549
if (_annotationIntrospector != null) {
@@ -890,15 +894,15 @@ protected AnnotatedConstructor _constructNonDefaultConstructor(ClassUtil.Ctor ct
890894
_emptyAnnotationMap(), _emptyAnnotationMaps(paramCount));
891895
}
892896

893-
/* [JACKSON-701]: Looks like JDK has discrepancy, whereas annotations for implicit 'this'
894-
* (for non-static inner classes) are NOT included, but type is? Strange, sounds like
895-
* a bug. Alas, we can't really fix that...
897+
/* Looks like JDK has discrepancy, whereas annotations for implicit 'this'
898+
* (for non-static inner classes) are NOT included, but type is?
899+
* Strange, sounds like a bug. Alas, we can't really fix that...
896900
*/
897901
if (paramCount == 0) { // no-arg default constructors, can simplify slightly
898902
return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
899903
_collectRelevantAnnotations(ctor.getDeclaredAnnotations()), NO_ANNOTATION_MAPS);
900904
}
901-
// Also: [JACKSON-757] (enum value constructors)
905+
// Also: enum value constructors
902906
AnnotationMap[] resolvedAnnotations;
903907
Annotation[][] paramAnns = ctor.getParameterAnnotations();
904908
if (paramCount != paramAnns.length) {

src/test/java/com/fasterxml/jackson/failing/TypeRefinementForMap1215Test.java

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.Map;
55

66
import com.fasterxml.jackson.annotation.JsonCreator;
7-
import com.fasterxml.jackson.annotation.JsonProperty;
7+
88
import com.fasterxml.jackson.databind.BaseMapTest;
99
import com.fasterxml.jackson.databind.ObjectMapper;
1010
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -13,10 +13,6 @@ public class TypeRefinementForMap1215Test extends BaseMapTest
1313
{
1414
interface HasUniqueId<K> {
1515
K getId();
16-
String getIdFieldName();
17-
}
18-
interface AnotherMap<K, V extends HasUniqueId<K>> extends Map<K, V> {
19-
public void add(V v);
2016
}
2117

2218
static class Item implements HasUniqueId<String>
@@ -26,58 +22,30 @@ static class Item implements HasUniqueId<String>
2622

2723
@Override
2824
public String getId() { return id; }
29-
30-
@Override
31-
public String getIdFieldName() {
32-
return "id";
33-
}
3425
}
3526

3627
static class Data
3728
{
3829
public String id;
3930

40-
@JsonProperty
41-
private Map<String, Item> items;
42-
43-
public Data() { }
44-
45-
public Map<String, Item> getItems() {
46-
return items;
47-
}
48-
4931
@JsonDeserialize(as = MyHashMap.class)
50-
public void setItems(Map<String, Item> items) {
51-
this.items = items;
52-
}
32+
public Map<String, Item> items;
33+
34+
// Would work with straight arguments:
35+
// public MyHashMap<String, Item> items;
5336
}
5437

5538
@SuppressWarnings("serial")
5639
static class MyHashMap<K, V extends HasUniqueId<K>>
5740
extends LinkedHashMap<K, V>
58-
implements AnotherMap<K, V>
5941
{
6042
@JsonCreator(mode=JsonCreator.Mode.DELEGATING)
6143
public MyHashMap(V[] values) {
6244
for (int i = 0; i < values.length; i++) {
6345
V v = values[i];
64-
if (v.getId() == null) {
65-
throw new RuntimeException("Failed to get id");
66-
}
67-
if (containsKey(v.getId())) {
68-
throw new RuntimeException("Conflict on id");
69-
}
7046
put(v.getId(), v);
7147
}
7248
}
73-
74-
@Override
75-
public void add(V v) {
76-
if (containsKey(v.getId())) {
77-
throw new RuntimeException("Conflict on add of id");
78-
}
79-
put(v.getId(), v);
80-
}
8149
}
8250

8351
/*
@@ -99,6 +67,8 @@ public void testMapRefinement() throws Exception
9967
assertEquals(ID1, data.id);
10068
assertNotNull(data.items);
10169
assertEquals(1, data.items.size());
102-
assertEquals(ID2, data.items.get(0).id);
70+
Item value = data.items.get(ID2);
71+
assertNotNull(value);
72+
assertEquals("value", value.property);
10373
}
10474
}

0 commit comments

Comments
 (0)