Skip to content

Commit 559cd04

Browse files
committed
Merge branch '2.15' into 2.16
2 parents f083348 + 4e1c9be commit 559cd04

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.fasterxml.jackson.databind.records;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.databind.*;
5+
6+
public class RecordFailingSetter3938Test extends BaseMapTest
7+
{
8+
private final static String ERROR_3938_PREFIX = "Non-null 'options' not allowed for ";
9+
10+
// [databind#3938]
11+
interface NoOptionsCommand {
12+
@JsonProperty("options")
13+
default void setOptions(JsonNode value) {
14+
if (value.isNull()) {
15+
return;
16+
}
17+
throw new IllegalArgumentException(ERROR_3938_PREFIX+getClass().getName());
18+
}
19+
}
20+
21+
public record Command3938(int id, String filter) implements NoOptionsCommand { }
22+
23+
private final ObjectMapper MAPPER = newJsonMapper();
24+
25+
// [databind#3938]: Should detect and use setters too
26+
public void testFailingSetter3939() throws Exception
27+
{
28+
final ObjectReader R = MAPPER.readerFor(Command3938.class);
29+
30+
// First, missing value and `null` are fine, as long as we have all fields
31+
assertNotNull(R.readValue(a2q("{'id':1, 'filter':'abc'}")));
32+
assertNotNull(R.readValue(a2q("{'id':2, 'filter':'abc', 'options':null}")));
33+
34+
// But then failure for non-empty Array (f.ex)
35+
try {
36+
R.readValue(a2q("{'id':2,'options':[123]}}"));
37+
fail("Should not pass");
38+
} catch (DatabindException e) {
39+
verifyException(e, ERROR_3938_PREFIX);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)