Skip to content

Commit d7155de

Browse files
committed
Fix #1493
1 parent 7fe2d4f commit d7155de

File tree

3 files changed

+28
-43
lines changed

3 files changed

+28
-43
lines changed

release-notes/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Project: jackson-databind
2-
32
------------------------------------------------------------------------
43
=== Releases ===
54
------------------------------------------------------------------------
@@ -17,6 +16,7 @@ Project: jackson-databind
1716
#1456: `TypeFactory` type resolution broken in 2.7 for generic types
1817
when using `constructType` with context
1918
#1473: Add explicit deserializer for `StringBuilder` due to Java 9 changes
19+
#1493: `ACCEPT_CASE_INSENSITIVE_PROPERTIES` fails with `@JsonUnwrapped`
2020

2121
2.8.5 (14-Nov-2016)
2222

src/main/java/com/fasterxml/jackson/databind/deser/impl/BeanPropertyMap.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public BeanPropertyMap withCaseInsensitivity(boolean state) {
9292
protected void init(Collection<SettableBeanProperty> props)
9393
{
9494
_size = props.size();
95-
95+
9696
// First: calculate size of primary hash area
9797
final int hashSize = findSize(_size);
9898
_hashMask = hashSize-1;
@@ -423,7 +423,8 @@ private final SettableBeanProperty _find2(String key, int slot, Object match)
423423
* Specialized method for removing specified existing entry.
424424
* NOTE: entry MUST exist, otherwise an exception is thrown.
425425
*/
426-
public void remove(SettableBeanProperty propToRm) {
426+
public void remove(SettableBeanProperty propToRm)
427+
{
427428
ArrayList<SettableBeanProperty> props = new ArrayList<SettableBeanProperty>(_size);
428429
String key = getPropertyName(propToRm);
429430
boolean found = false;
@@ -434,7 +435,9 @@ public void remove(SettableBeanProperty propToRm) {
434435
continue;
435436
}
436437
if (!found) {
437-
found = key.equals(prop.getName());
438+
// 09-Jan-2017, tatu: Important: must check name slot and NOT property name,
439+
// as only former is lower-case in case-insensitive case
440+
found = key.equals(_hashArea[i-1]);
438441
if (found) {
439442
// need to leave a hole here
440443
_propsInOrder[_findFromOrdered(prop)] = null;

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

+21-39
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ static class Outer {
9797
private Inner inner;
9898
}
9999

100+
// [databind#1493]: case-insensitive handling
101+
static class Person {
102+
@JsonUnwrapped(prefix = "businessAddress.")
103+
public Address businessAddress;
104+
}
105+
106+
static class Address {
107+
public String street;
108+
public String addon;
109+
public String zip;
110+
public String town;
111+
public String country;
112+
}
113+
100114
/*
101115
/**********************************************************
102116
/* Tests, serialization
@@ -192,45 +206,13 @@ public void testUnwrappedAsPropertyIndicator() throws Exception
192206
assertTrue(actual.contains("Zebra"));
193207
assertFalse(actual.contains("inner"));
194208
}
195-
196-
// 22-Apr-2013, tatu: Commented out as it can't be simply fixed; requires implementing
197-
// deep-update/merge. But leaving here to help with that effort, if/when it proceeds.
198-
199-
/*
200-
// [databind#211]: Actually just variant of #160
201-
202-
static class Issue211Bean {
203-
public String test1;
204-
205-
public String test2;
206-
@JsonUnwrapped
207-
public Issue211Unwrapped unwrapped;
208-
}
209209

210-
static class Issue211Unwrapped {
211-
public String test3;
212-
public String test4;
213-
}
214-
215-
public void testIssue211() throws Exception
210+
// [databind#1493]: case-insensitive handling
211+
public void testCaseInsensitiveUnwrap() throws Exception
216212
{
217-
Issue211Bean bean = new Issue211Bean();
218-
bean.test1 = "Field 1";
219-
bean.test2 = "Field 2";
220-
Issue211Unwrapped tJackson2 = new Issue211Unwrapped();
221-
tJackson2.test3 = "Field 3";
222-
tJackson2.test4 = "Field 4";
223-
bean.unwrapped = tJackson2;
224-
225-
final String JSON = "{\"test1\": \"Field 1 merged\", \"test3\": \"Field 3 merged\"}";
226-
ObjectMapper o = new ObjectMapper();
227-
Issue211Bean result = o.readerForUpdating(bean).withType(Issue211Bean.class).readValue(JSON);
228-
assertSame(bean, result);
229-
assertEquals("Field 1 merged", result.test1);
230-
assertEquals("Field 2", result.test2);
231-
assertNotNull(result.unwrapped);
232-
assertEquals("Field 3 merged", result.unwrapped.test3);
233-
assertEquals("Field 4", result.unwrapped.test4);
234-
}
235-
*/
213+
ObjectMapper mapper = new ObjectMapper();
214+
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
215+
Person p = mapper.readValue("{ }", Person.class);
216+
assertNotNull(p);
217+
}
236218
}

0 commit comments

Comments
 (0)