Skip to content

Commit 660ec8f

Browse files
committed
Fix #1013
1 parent 1ed7f38 commit 660ec8f

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

release-notes/CREDITS

+4
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,7 @@ Ievgen Pianov (pyanoveugen@github)
350350
Jayson Minard (apatrida@github)
351351
* Reported #1005: Synthetic constructors confusing Jackson data binding
352352
(2.6.4)
353+
354+
David Bakin (david-bakin@github)
355+
* Reported #1013: `@JsonUnwrapped` is not treated as assuming `@JsonProperty("")`
356+
(2.6.4)

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Project: jackson-databind
1212
(reported by Ievgen P)
1313
#1005: Synthetic constructors confusing Jackson data binding
1414
(reported by Jayson M)
15+
#1013: `@JsonUnwrapped` is not treated as assuming `@JsonProperty("")`
16+
(reported by David B)
1517
- Fix a minor problem with `@JsonNaming` not recognizing default value
1618

1719
2.6.3 (12-Oct-2015)

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,16 @@ public PropertyName findNameForSerialization(Annotated a)
739739
JsonProperty pann = _findAnnotation(a, JsonProperty.class);
740740
if (pann != null) {
741741
name = pann.value();
742+
/* 22-Apr-2014, tatu: Should figure out a better way to do this, but
743+
* it's actually bit tricky to do it more efficiently (meta-annotations
744+
* add more lookups; AnnotationMap costs etc)
745+
*/
742746
} else if (_hasAnnotation(a, JsonSerialize.class)
743747
|| _hasAnnotation(a, JsonView.class)
744-
|| _hasAnnotation(a, JsonRawValue.class)) {
748+
|| _hasAnnotation(a, JsonRawValue.class)
749+
|| _hasAnnotation(a, JsonUnwrapped.class)
750+
|| _hasAnnotation(a, JsonBackReference.class)
751+
|| _hasAnnotation(a, JsonManagedReference.class)) {
745752
name = "";
746753
} else {
747754
return null;

src/test/java/com/fasterxml/jackson/databind/struct/TestUnwrapped.java

+29-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.fasterxml.jackson.databind.*;
66

77
/**
8-
* Unit tests for verifying [JACKSON-132] implementation.
8+
* Unit tests for verifying that basic {@link JsonUnwrapped} annotation
9+
* handling works as expected; some more advanced tests are separated out
10+
* to more specific test classes (like prefix/suffix handling).
911
*/
1012
public class TestUnwrapped extends BaseMapTest
1113
{
@@ -85,6 +87,16 @@ public Child() { }
8587
public Child(String f) { field = f; }
8688
}
8789

90+
static class Inner {
91+
public String animal;
92+
}
93+
94+
static class Outer {
95+
// @JsonProperty
96+
@JsonUnwrapped
97+
private Inner inner;
98+
}
99+
88100
/*
89101
/**********************************************************
90102
/* Tests, serialization
@@ -166,11 +178,26 @@ public void testIssue615() throws Exception
166178
assertEquals("name", output.c1.field);
167179
}
168180

181+
public void testUnwrappedAsPropertyIndicator() throws Exception
182+
{
183+
Inner inner = new Inner();
184+
inner.animal = "Zebra";
185+
186+
Outer outer = new Outer();
187+
outer.inner = inner;
188+
189+
String actual = MAPPER.writeValueAsString(outer);
190+
191+
assertTrue(actual.contains("animal"));
192+
assertTrue(actual.contains("Zebra"));
193+
assertFalse(actual.contains("inner"));
194+
}
195+
169196
// 22-Apr-2013, tatu: Commented out as it can't be simply fixed; requires implementing
170197
// deep-update/merge. But leaving here to help with that effort, if/when it proceeds.
171198

172199
/*
173-
// [Issue#211]: Actually just variant of #160
200+
// [databind#211]: Actually just variant of #160
174201
175202
static class Issue211Bean {
176203
public String test1;

0 commit comments

Comments
 (0)