Skip to content

Commit fdd9596

Browse files
committed
test cleanup
1 parent fbc1fa2 commit fdd9596

File tree

2 files changed

+101
-117
lines changed

2 files changed

+101
-117
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/TestAnyProperties.java

Lines changed: 101 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,77 @@ public void prop(String name, Base value) {
135135
}
136136
}
137137

138-
static class JsonAnySetterOnMap {
139-
public int id;
138+
static class JsonAnySetterOnMap {
139+
public int id;
140140

141-
@JsonAnySetter
142-
protected HashMap<String, String> other = new HashMap<String, String>();
143-
144-
@JsonAnyGetter
145-
public Map<String, String> any() {
146-
return other;
147-
}
141+
@JsonAnySetter
142+
protected HashMap<String, String> other = new HashMap<String, String>();
148143

149-
}
144+
@JsonAnyGetter
145+
public Map<String, String> any() {
146+
return other;
147+
}
148+
}
150149

151-
static class JsonAnySetterOnNullMap {
152-
public int id;
150+
static class JsonAnySetterOnNullMap {
151+
public int id;
153152

154-
@JsonAnySetter
155-
protected HashMap<String, String> other;
153+
@JsonAnySetter
154+
protected HashMap<String, String> other;
156155

157-
@JsonAnyGetter
158-
public Map<String, String> any() {
159-
return other;
160-
}
156+
@JsonAnyGetter
157+
public Map<String, String> any() {
158+
return other;
159+
}
160+
}
161161

162-
}
162+
static class MyGeneric<T>
163+
{
164+
private String staticallyMappedProperty;
165+
private Map<T, Integer> dynamicallyMappedProperties = new HashMap<T, Integer>();
166+
167+
public String getStaticallyMappedProperty() {
168+
return staticallyMappedProperty;
169+
}
170+
171+
@JsonAnySetter
172+
public void addDynamicallyMappedProperty(T key, int value) {
173+
dynamicallyMappedProperties.put(key, value);
174+
}
163175

176+
public void setStaticallyMappedProperty(String staticallyMappedProperty) {
177+
this.staticallyMappedProperty = staticallyMappedProperty;
178+
}
164179

165-
/*
180+
@JsonAnyGetter
181+
public Map<T, Integer> getDynamicallyMappedProperties() {
182+
return dynamicallyMappedProperties;
183+
}
184+
}
185+
186+
static class MyWrapper
187+
{
188+
private MyGeneric<String> myStringGeneric;
189+
private MyGeneric<Integer> myIntegerGeneric;
190+
191+
public MyGeneric<String> getMyStringGeneric() {
192+
return myStringGeneric;
193+
}
194+
195+
public void setMyStringGeneric(MyGeneric<String> myStringGeneric) {
196+
this.myStringGeneric = myStringGeneric;
197+
}
198+
199+
public MyGeneric<Integer> getMyIntegerGeneric() {
200+
return myIntegerGeneric;
201+
}
202+
203+
public void setMyIntegerGeneric(MyGeneric<Integer> myIntegerGeneric) {
204+
this.myIntegerGeneric = myIntegerGeneric;
205+
}
206+
}
207+
208+
/*
166209
/**********************************************************
167210
/* Test methods
168211
/**********************************************************
@@ -264,9 +307,44 @@ public void testJsonAnySetterOnNullMap() throws Exception {
264307
JsonAnySetterOnNullMap.class);
265308
assertEquals(2, result.id);
266309
assertNull(result.other);
267-
}
268-
269-
/*
310+
}
311+
312+
// [databind#1035]
313+
public void testGenericAnySetter() throws Exception
314+
{
315+
ObjectMapper mapper = new ObjectMapper();
316+
317+
Map<String, Integer> stringGenericMap = new HashMap<String, Integer>();
318+
stringGenericMap.put("testStringKey", 5);
319+
Map<Integer, Integer> integerGenericMap = new HashMap<Integer, Integer>();
320+
integerGenericMap.put(111, 6);
321+
322+
MyWrapper deserialized = mapper.readValue(aposToQuotes(
323+
"{'myStringGeneric':{'staticallyMappedProperty':'Test','testStringKey':5},'myIntegerGeneric':{'staticallyMappedProperty':'Test2','111':6}}"
324+
), MyWrapper.class);
325+
MyGeneric<String> stringGeneric = deserialized.getMyStringGeneric();
326+
MyGeneric<Integer> integerGeneric = deserialized.getMyIntegerGeneric();
327+
328+
assertNotNull(stringGeneric);
329+
assertEquals(stringGeneric.getStaticallyMappedProperty(), "Test");
330+
for(Map.Entry<String, Integer> entry : stringGeneric.getDynamicallyMappedProperties().entrySet()) {
331+
assertTrue("A key in MyGeneric<String> is not an String.", entry.getKey() instanceof String);
332+
assertTrue("A value in MyGeneric<Integer> is not an Integer.", entry.getValue() instanceof Integer);
333+
}
334+
assertEquals(stringGeneric.getDynamicallyMappedProperties(), stringGenericMap);
335+
336+
assertNotNull(integerGeneric);
337+
assertEquals(integerGeneric.getStaticallyMappedProperty(), "Test2");
338+
for(Map.Entry<Integer, Integer> entry : integerGeneric.getDynamicallyMappedProperties().entrySet()) {
339+
Object key = entry.getKey();
340+
assertEquals("A key in MyGeneric<Integer> is not an Integer.", Integer.class, key.getClass());
341+
Object value = entry.getValue();
342+
assertEquals("A value in MyGeneric<Integer> is not an Integer.", Integer.class, value.getClass());
343+
}
344+
assertEquals(integerGeneric.getDynamicallyMappedProperties(), integerGenericMap);
345+
}
346+
347+
/*
270348
/**********************************************************
271349
/* Private helper methods
272350
/**********************************************************

src/test/java/com/fasterxml/jackson/failing/AnySetter1035Test.java

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)