-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98d5eed
commit aea1ccc
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/test/java/com/fasterxml/jackson/databind/tofix/JsonCreatorNoArgs4777Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.fasterxml.jackson.databind.tofix; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.deser.*; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class JsonCreatorNoArgs4777Test extends DatabindTestUtil | ||
{ | ||
static class Foo { | ||
private Foo() { } | ||
|
||
@JsonCreator | ||
static Foo create() { | ||
return new Foo(); | ||
} | ||
} | ||
|
||
static class Instantiators implements ValueInstantiators { | ||
@Override | ||
public ValueInstantiator findValueInstantiator( | ||
DeserializationConfig config, | ||
BeanDescription beanDesc, | ||
ValueInstantiator defaultInstantiator | ||
) { | ||
if (beanDesc.getBeanClass() == Foo.class) { | ||
AnnotatedWithParams dc = defaultInstantiator.getDefaultCreator(); | ||
if (!(dc instanceof AnnotatedMethod) | ||
|| !dc.getName().equals("create")) { | ||
throw new IllegalArgumentException("Wrong DefaultCreator: should be static-method 'create()', is: " | ||
+dc); | ||
} | ||
} | ||
return defaultInstantiator; | ||
} | ||
} | ||
|
||
// For [databind#4777] | ||
@SuppressWarnings("serial") | ||
@Test | ||
@JacksonTestFailureExpected | ||
public void testCreatorDetection4777() throws Exception { | ||
SimpleModule sm = new SimpleModule() { | ||
@Override | ||
public void setupModule(SetupContext context) { | ||
super.setupModule(context); | ||
context.addValueInstantiators(new Instantiators()); | ||
} | ||
}; | ||
ObjectMapper mapper = JsonMapper.builder().addModule(sm).build(); | ||
|
||
Foo result = mapper.readValue("{}", Foo.class); | ||
assertNotNull(result); | ||
} | ||
} |