Skip to content

Commit

Permalink
Fix #1804
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 24, 2017
1 parent 4675896 commit a1404d5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
3 changes: 2 additions & 1 deletion release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Project: jackson-databind
(reported by nhtzr@github)
#1768: Improve `TypeFactory.constructFromCanonical()` to work with
`java.lang.reflect.Type.getTypeName()` format

#1804: `ValueInstantiator.canInstantiate()` ignores `canCreateUsingArrayDelegate()`
(reported byb henryptung@github)

2.8.10 (24-Aug-2017)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,6 @@ public JsonDeserializer<Object> buildBeanDeserializer(DeserializationContext ctx
}
JsonDeserializer<?> deserializer;

/* 19-Mar-2012, tatu: This check used to be done earlier; but we have to defer
* it a bit to collect information on ObjectIdReader, for example.
*/
if (type.isAbstract() && !valueInstantiator.canInstantiate()) {
deserializer = builder.buildAbstract();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ public String getValueTypeDesc() {
* be created.
*/
public boolean canInstantiate() {
return canCreateUsingDefault() || canCreateUsingDelegate()
|| canCreateFromObjectWith() || canCreateFromString()
|| canCreateFromInt() || canCreateFromLong()
|| canCreateFromDouble() || canCreateFromBoolean();
}
return canCreateUsingDefault()
|| canCreateUsingDelegate() || canCreateUsingArrayDelegate()
|| canCreateFromObjectWith() || canCreateFromString()
|| canCreateFromInt() || canCreateFromLong()
|| canCreateFromDouble() || canCreateFromBoolean();
}

/**
* Method that can be called to check whether a String-based creator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public String getValueTypeDesc() {
public Class<?> getValueClass() {
return _valueClass;
}

@Override
public boolean canCreateFromString() {
return (_fromStringCreator != null);
Expand All @@ -208,27 +208,36 @@ public boolean canCreateFromDouble() {
public boolean canCreateFromBoolean() {
return (_fromBooleanCreator != null);
}

@Override
public boolean canCreateUsingDefault() {
return (_defaultCreator != null);
}

@Override
public boolean canCreateUsingDelegate() {
return _delegateType != null;
return (_delegateType != null);
}

@Override
public boolean canCreateUsingArrayDelegate() {
return _arrayDelegateType != null;
return (_arrayDelegateType != null);
}

@Override
public boolean canCreateFromObjectWith() {
return (_withArgsCreator != null);
}

@Override
public boolean canInstantiate() {
return canCreateUsingDefault()
|| canCreateUsingDelegate() || canCreateUsingArrayDelegate()
|| canCreateFromObjectWith() || canCreateFromString()
|| canCreateFromInt() || canCreateFromLong()
|| canCreateFromDouble() || canCreateFromBoolean();
}

@Override
public JavaType getDelegateType(DeserializationConfig config) {
return _delegateType;
Expand Down Expand Up @@ -263,7 +272,7 @@ public Object createUsingDefault(DeserializationContext ctxt) throws IOException
null, rewrapCtorProblem(ctxt, t));
}
}

@Override
public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.fasterxml.jackson.databind.creators;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;

public class DelegatingArrayCreator1804Test extends BaseMapTest
{
public static class MyTypeImpl extends MyType {
private final List<Integer> values;

MyTypeImpl(List<Integer> values) {
this.values = values;
}

@Override
public List<Integer> getValues() {
return values;
}
}

static abstract class MyType {
@JsonValue
public abstract List<Integer> getValues();

@JsonCreator(mode=JsonCreator.Mode.DELEGATING)
public static MyType of(List<Integer> values) {
return new MyTypeImpl(values);
}
}


public void testDelegatingArray1804() throws Exception {
ObjectMapper mapper = new ObjectMapper();
MyType thing = mapper.readValue("[]", MyType.class);
assertNotNull(thing);
}
}

0 comments on commit a1404d5

Please sign in to comment.