Skip to content

(WIP) Fix #4310: make @ConstructorProperties names be explicit #5221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
String propName = p.currentName();
p.nextToken(); // to point to value
final SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
//System.err.println("propName: "+propName+", prop: "+creatorProp+" (from "+creator.properties()+")");
// Object Id property?
if (buffer.readIdProperty(propName) && creatorProp == null) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.*;

import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*;

public class CreatorPropertiesTest
public class CreatorPropertiesTest extends DatabindTestUtil
{
static class Issue905Bean {
// 08-Nov-2015, tatu: Note that in real code we would most likely use same
Expand Down Expand Up @@ -83,6 +84,24 @@ public Value3252(@JsonProperty("name") String name,
}
}

// [databind#4310]
static final class Test4310
{
private final String value;

@ConstructorProperties("value")
public Test4310(@ImplicitName("somethingElse") String v) {
if (v == null) {
throw new IllegalArgumentException("Constructor called with null value");
}
value = v;
}

public String getValue() {
return value;
}
}

/*
/**********************************************************
/* Test methods
Expand Down Expand Up @@ -149,6 +168,20 @@ public void testSkipNonScalar3252() throws Exception
assertEquals(3, testData.size());
}

// [databind#4310]: use of ConstructorProperties with ParameterNames module
@Test
public void issue4310() throws Exception
{
ObjectMapper mapper = jsonMapperBuilder()
.annotationIntrospector(new AnnotationIntrospectorPair(
new ImplicitNameIntrospector(), new JacksonAnnotationIntrospector()))
.build();
String json = mapper.writeValueAsString(new Test4310("foo"));
//System.err.println("JSON: "+json);
Test4310 result = mapper.readValue(json, Test4310.class);
assertEquals("foo", result.getValue());
}

static class Something4908 {
@JsonProperty("value")
private final String _value;
Expand Down
Loading