Skip to content

Commit 6c782df

Browse files
committed
Merge minor pieces of #4515 work, test improvements etc
1 parent ba4cf06 commit 6c782df

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ protected void _validateNamedPropertyParameter(DeserializationContext ctxt,
11551155
// Must be injectable or have name; without either won't work
11561156
if ((name == null) && (injectId == null)) {
11571157
ctxt.reportBadTypeDefinition(beanDesc,
1158-
"Argument #%d of constructor %s has no property name (and is not Injectable): can not use as property-based Creator",
1158+
"Argument #%d of Creator %s has no property name (and is not Injectable): can not use as property-based Creator",
11591159
paramIndex, candidate);
11601160
}
11611161
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.fasterxml.jackson.databind.deser.creators;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.fasterxml.jackson.annotation.JsonCreator;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
12+
13+
/**
14+
* Tests to help cover simpler cases wrt [databind#4515]
15+
*/
16+
public class Creators4515Test extends DatabindTestUtil
17+
{
18+
static class ConstructorBeanPropsExplicit {
19+
int x;
20+
21+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
22+
protected ConstructorBeanPropsExplicit(@JsonProperty("x") int x) {
23+
this.x = x;
24+
}
25+
}
26+
27+
static class ConstructorBeanPropsWithName {
28+
int x;
29+
30+
@JsonCreator
31+
protected ConstructorBeanPropsWithName(@JsonProperty("x") int x) {
32+
this.x = x;
33+
}
34+
}
35+
36+
static class FactoryBeanPropsExplicit {
37+
double d;
38+
39+
private FactoryBeanPropsExplicit(double value, boolean dummy) { d = value; }
40+
41+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
42+
protected static FactoryBeanPropsExplicit createIt(@JsonProperty("f") double value) {
43+
return new FactoryBeanPropsExplicit(value, true);
44+
}
45+
}
46+
47+
/*
48+
/**********************************************************************
49+
/* Test methods, simple Properties-based (constructor) explicitly annotated
50+
/**********************************************************************
51+
*/
52+
53+
private final ObjectMapper MAPPER = newJsonMapper();
54+
55+
@Test
56+
public void testPropsBasedConstructorExplicit() throws Exception
57+
{
58+
ConstructorBeanPropsExplicit bean = MAPPER.readValue("{ \"x\" : 42 }",
59+
ConstructorBeanPropsExplicit.class);
60+
assertEquals(42, bean.x);
61+
}
62+
63+
@Test
64+
public void testPropsBasedConstructorWithName() throws Exception
65+
{
66+
ConstructorBeanPropsWithName bean = MAPPER.readValue("{ \"x\" : 28 }",
67+
ConstructorBeanPropsWithName.class);
68+
assertEquals(28, bean.x);
69+
}
70+
71+
/*
72+
/**********************************************************************
73+
/* Test methods, simple Properties-based (constructor) explicitly annotated
74+
/**********************************************************************
75+
*/
76+
77+
@Test
78+
public void testPropsBasedFactoryExplicit() throws Exception
79+
{
80+
FactoryBeanPropsExplicit bean = MAPPER.readValue("{ \"f\" : 0.5 }",
81+
FactoryBeanPropsExplicit.class);
82+
assertEquals(0.5, bean.d);
83+
}
84+
85+
/*
86+
/**********************************************************************
87+
/* Test methods, simple Delegating, explicitly annotated
88+
/**********************************************************************
89+
*/
90+
91+
}

src/test/java/com/fasterxml/jackson/databind/testutil/DatabindTestUtil.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,12 @@ public static TypeFactory newTypeFactory() {
354354
*/
355355

356356
public static ObjectMapper newJsonMapper() {
357-
return new JsonMapper();
357+
return jsonMapperBuilder().build();
358358
}
359359

360360
public static JsonMapper.Builder jsonMapperBuilder() {
361-
return JsonMapper.builder();
361+
return JsonMapper.builder()
362+
.enable(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION);
362363
}
363364

364365
/*

0 commit comments

Comments
 (0)