Skip to content

Commit

Permalink
Add failing test for #2977
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 28, 2020
1 parent 8b0ca0b commit 1f7bcdc
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.ConstructorDetector;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;

public class CreatorNullPrimitives2977Test extends BaseMapTest
{
@SuppressWarnings("serial")
static class ABCParamIntrospector extends JacksonAnnotationIntrospector
{
@Override
public String findImplicitPropertyName(AnnotatedMember param) {
if (param instanceof AnnotatedParameter) {
AnnotatedParameter ap = (AnnotatedParameter) param;
switch (ap.getIndex()) {
case 0: return "a";
case 1: return "b";
case 2: return "c";
default:
return "param"+ap.getIndex();
}
}
return super.findImplicitPropertyName(param);
}
}

static class TestClass2977 {
@JsonProperty("aa")
final int a;

// work-around: add JsonProperty on parameter name, or JsonCreator
// @com.fasterxml.jackson.annotation.JsonCreator
public TestClass2977(int a) {
this.a = a;
}
}

// [databind#2977]
public void testDefaultingWithNull2977() throws Exception
{
ObjectMapper mapper = jsonMapperBuilder()
.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
.annotationIntrospector(new ABCParamIntrospector())
.constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED)
.build();
TestClass2977 result = mapper.readValue(a2q("{'aa': 8}"), TestClass2977.class);
assertEquals(8, result.a);
}
}

0 comments on commit 1f7bcdc

Please sign in to comment.