Skip to content

Commit 229ddd0

Browse files
committed
Start wrok on #3394, allow @JsonAnySetter on JsonNode valued field
1 parent 7f1a3db commit 229ddd0

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/main/java/com/fasterxml/jackson/databind/introspect/BasicBeanDescription.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,10 @@ public AnnotatedMember findAnySetterAccessor() throws IllegalArgumentException
322322
// For now let's require a Map; in future can add support for other
323323
// types like perhaps Iterable<Map.Entry>?
324324
Class<?> type = anyField.getRawType();
325-
if (!Map.class.isAssignableFrom(type)) {
325+
if (!Map.class.isAssignableFrom(type)
326+
&& !JsonNode.class.isAssignableFrom(type)) {
326327
throw new IllegalArgumentException(String.format(
327-
"Invalid 'any-setter' annotation on field '%s': type is not instance of java.util.Map",
328+
"Invalid 'any-setter' annotation on field '%s': type is not instance of `java.util.Map` or `JsonNode`",
328329
anyField.getName()));
329330
}
330331
return anyField;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fasterxml.jackson.databind.deser;
2+
3+
import com.fasterxml.jackson.annotation.JsonAnySetter;
4+
5+
import com.fasterxml.jackson.databind.*;
6+
7+
// for [databind#3394]
8+
public class AnySetter3394Test extends BaseMapTest
9+
{
10+
static class AnySetter3394Bean {
11+
@JsonAnySetter
12+
public JsonNode extraData;
13+
}
14+
15+
/*
16+
/**********************************************************
17+
/* Test methods
18+
/**********************************************************
19+
*/
20+
21+
private final ObjectMapper MAPPER = newJsonMapper();
22+
23+
public void testAnySetterWithJsonNode() throws Exception
24+
{
25+
final String DOC = a2q("{'test': 3}");
26+
AnySetter3394Bean bean = MAPPER.readValue(DOC, AnySetter3394Bean.class);
27+
assertEquals(DOC, ""+bean.extraData);
28+
}
29+
}

0 commit comments

Comments
 (0)