Skip to content

Commit 00cf97c

Browse files
committed
Add test for #1432
1 parent ad31a7d commit 00cf97c

File tree

2 files changed

+139
-2
lines changed

2 files changed

+139
-2
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/TestCustomValueInstDefaults.java renamed to src/test/java/com/fasterxml/jackson/databind/creators/TestCustomValueInstDefaults.java

+138-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
package com.fasterxml.jackson.databind.deser;
1+
package com.fasterxml.jackson.databind.creators;
2+
3+
import java.io.IOException;
24

35
import com.fasterxml.jackson.annotation.*;
6+
import com.fasterxml.jackson.core.Version;
47
import com.fasterxml.jackson.databind.*;
8+
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
9+
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
10+
import com.fasterxml.jackson.databind.deser.ValueInstantiators;
511
import com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer;
612
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator;
713
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -262,6 +268,112 @@ public void setupModule(SetupContext context)
262268
}
263269
}
264270

271+
static class ClassWith32Props {
272+
@JsonCreator
273+
public ClassWith32Props(@JsonProperty("p1") String p1,
274+
@JsonProperty("p2") String p2,
275+
@JsonProperty("p3") String p3, @JsonProperty("p4") String p4,
276+
@JsonProperty("p5") String p5, @JsonProperty("p6") String p6,
277+
@JsonProperty("p7") String p7, @JsonProperty("p8") String p8,
278+
@JsonProperty("p9") String p9, @JsonProperty("p10") String p10,
279+
@JsonProperty("p11") String p11, @JsonProperty("p12") String p12,
280+
@JsonProperty("p13") String p13, @JsonProperty("p14") String p14,
281+
@JsonProperty("p15") String p15, @JsonProperty("p16") String p16,
282+
@JsonProperty("p17") String p17, @JsonProperty("p18") String p18,
283+
@JsonProperty("p19") String p19, @JsonProperty("p20") String p20,
284+
@JsonProperty("p21") String p21, @JsonProperty("p22") String p22,
285+
@JsonProperty("p23") String p23, @JsonProperty("p24") String p24,
286+
@JsonProperty("p25") String p25, @JsonProperty("p26") String p26,
287+
@JsonProperty("p27") String p27, @JsonProperty("p28") String p28,
288+
@JsonProperty("p29") String p29, @JsonProperty("p30") String p30,
289+
@JsonProperty("p31") String p31, @JsonProperty("p32") String p32) {
290+
this.p1 = p1;
291+
this.p2 = p2;
292+
this.p3 = p3;
293+
this.p4 = p4;
294+
this.p5 = p5;
295+
this.p6 = p6;
296+
this.p7 = p7;
297+
this.p8 = p8;
298+
this.p9 = p9;
299+
this.p10 = p10;
300+
this.p11 = p11;
301+
this.p12 = p12;
302+
this.p13 = p13;
303+
this.p14 = p14;
304+
this.p15 = p15;
305+
this.p16 = p16;
306+
this.p17 = p17;
307+
this.p18 = p18;
308+
this.p19 = p19;
309+
this.p20 = p20;
310+
this.p21 = p21;
311+
this.p22 = p22;
312+
this.p23 = p23;
313+
this.p24 = p24;
314+
this.p25 = p25;
315+
this.p26 = p26;
316+
this.p27 = p27;
317+
this.p28 = p28;
318+
this.p29 = p29;
319+
this.p30 = p30;
320+
this.p31 = p31;
321+
this.p32 = p32;
322+
}
323+
324+
public final String p1, p2, p3, p4;
325+
public final String p5, p6, p7, p8;
326+
public final String p9, p10, p11, p12;
327+
public final String p13, p14, p15, p16;
328+
public final String p17, p18, p19, p20;
329+
public final String p21, p22, p23, p24;
330+
public final String p25, p26, p27, p28;
331+
public final String p29, p30, p31, p32;
332+
}
333+
334+
static class VerifyingValueInstantiator extends StdValueInstantiator {
335+
protected VerifyingValueInstantiator(StdValueInstantiator src) {
336+
super(src);
337+
}
338+
339+
@Override
340+
public Object createFromObjectWith(DeserializationContext ctxt, SettableBeanProperty[] props, PropertyValueBuffer buffer) throws IOException {
341+
for (SettableBeanProperty prop : props) {
342+
assertTrue("prop " + prop.getName() + " was expected to have buffer.hasParameter(prop) be true but was false", buffer.hasParameter(prop));
343+
}
344+
return super.createFromObjectWith(ctxt, props, buffer);
345+
}
346+
}
347+
348+
// [databind#1432]
349+
350+
public static class ClassWith32Module extends SimpleModule {
351+
public ClassWith32Module() {
352+
super("test", Version.unknownVersion());
353+
}
354+
355+
@Override
356+
public void setupModule(SetupContext context) {
357+
context.addValueInstantiators(new ValueInstantiators.Base() {
358+
@Override
359+
public ValueInstantiator findValueInstantiator(DeserializationConfig config,
360+
BeanDescription beanDesc, ValueInstantiator defaultInstantiator) {
361+
if (beanDesc.getBeanClass() == ClassWith32Props.class) {
362+
return new VerifyingValueInstantiator((StdValueInstantiator)
363+
defaultInstantiator);
364+
}
365+
return defaultInstantiator;
366+
}
367+
});
368+
}
369+
}
370+
371+
/*
372+
/**********************************************************
373+
/* Test methods
374+
/**********************************************************
375+
*/
376+
265377
// When all values are in the source, no defaults should be used.
266378
public void testAllPresent() throws Exception
267379
{
@@ -415,4 +527,29 @@ public void testMoreThan32CreatorParams() throws Exception
415527
assertEquals(BigBucket.DEFAULT_S, big.s15);
416528
assertEquals(BigBucket.DEFAULT_S, big.s16);
417529
}
530+
531+
// [databind#1432]
532+
public void testClassWith32CreatorParams() throws Exception
533+
{
534+
StringBuilder sb = new StringBuilder()
535+
.append("{\n");
536+
for (int i = 1; i <= 32; ++i) {
537+
sb.append("\"p").append(i).append("\" : \"NotNull")
538+
.append(i).append("\"");
539+
if (i < 32) {
540+
sb.append(",\n");
541+
}
542+
}
543+
sb.append("\n}\n");
544+
String json = sb.toString();
545+
ObjectMapper mapper = new ObjectMapper()
546+
.registerModule(new ClassWith32Module());
547+
ClassWith32Props result = mapper.readValue(json, ClassWith32Props.class);
548+
// let's assume couple of first, last ones suffice
549+
assertEquals("NotNull1", result.p1);
550+
assertEquals("NotNull2", result.p2);
551+
assertEquals("NotNull31", result.p31);
552+
assertEquals("NotNull32", result.p32);
553+
}
418554
}
555+

src/test/java/com/fasterxml/jackson/databind/seq/SequenceWriterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static class ImplB extends PolyBase {
4242

4343
public ImplB(int v) { b = v; }
4444
}
45-
45+
4646
/*
4747
/**********************************************************
4848
/* Test methods, simple writes

0 commit comments

Comments
 (0)