Skip to content

Commit

Permalink
Start wrok on #3394, allow @JsonAnySetter on JsonNode valued field
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 1, 2022
1 parent 7f1a3db commit 229ddd0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ public AnnotatedMember findAnySetterAccessor() throws IllegalArgumentException
// For now let's require a Map; in future can add support for other
// types like perhaps Iterable<Map.Entry>?
Class<?> type = anyField.getRawType();
if (!Map.class.isAssignableFrom(type)) {
if (!Map.class.isAssignableFrom(type)
&& !JsonNode.class.isAssignableFrom(type)) {
throw new IllegalArgumentException(String.format(
"Invalid 'any-setter' annotation on field '%s': type is not instance of java.util.Map",
"Invalid 'any-setter' annotation on field '%s': type is not instance of `java.util.Map` or `JsonNode`",
anyField.getName()));
}
return anyField;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.fasterxml.jackson.databind.deser;

import com.fasterxml.jackson.annotation.JsonAnySetter;

import com.fasterxml.jackson.databind.*;

// for [databind#3394]
public class AnySetter3394Test extends BaseMapTest
{
static class AnySetter3394Bean {
@JsonAnySetter
public JsonNode extraData;
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

private final ObjectMapper MAPPER = newJsonMapper();

public void testAnySetterWithJsonNode() throws Exception
{
final String DOC = a2q("{'test': 3}");
AnySetter3394Bean bean = MAPPER.readValue(DOC, AnySetter3394Bean.class);
assertEquals(DOC, ""+bean.extraData);
}
}

0 comments on commit 229ddd0

Please sign in to comment.