forked from FasterXML/jackson-databind
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/com/fasterxml/jackson/databind/type/NestedTypes1604Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.fasterxml.jackson.databind.type; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
// for [databind#1604] | ||
public class NestedTypes1604Test extends BaseMapTest { | ||
public static class Data<T> { | ||
private T data; | ||
|
||
public Data(T data) { | ||
this.data = data; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
public static <T> Data<List<T>> of(List<T> data) { | ||
return new DataList<>(data); | ||
} | ||
} | ||
|
||
public static class DataList<T> extends Data<List<T>> { | ||
public DataList(List<T> data) { | ||
super(data); | ||
} | ||
} | ||
|
||
public static class Inner { | ||
private int index; | ||
|
||
public Inner(int index) { | ||
this.index = index; | ||
} | ||
|
||
public int getIndex() { | ||
return index; | ||
} | ||
} | ||
|
||
public static class BadOuter { | ||
private Data<List<Inner>> inner; | ||
|
||
public BadOuter(Data<List<Inner>> inner) { | ||
this.inner = inner; | ||
} | ||
|
||
public Data<List<Inner>> getInner() { | ||
return inner; | ||
} | ||
} | ||
|
||
public static class GoodOuter { | ||
private DataList<Inner> inner; | ||
|
||
public GoodOuter(DataList<Inner> inner) { | ||
this.inner = inner; | ||
} | ||
|
||
public DataList<Inner> getInner() { | ||
return inner; | ||
} | ||
} | ||
|
||
public void testIssue1604() throws Exception { | ||
final ObjectMapper objectMapper = objectMapper(); | ||
List<Inner> inners = new ArrayList<>(); | ||
for (int i = 0; i < 2; i++) { | ||
inners.add(new Inner(i)); | ||
} | ||
String expectedJson = aposToQuotes("{'inner':{'data':[{'index':0},{'index':1}]}}"); | ||
assertEquals( | ||
expectedJson, | ||
objectMapper.writeValueAsString(new GoodOuter(new DataList<>(inners))) | ||
); | ||
assertEquals( | ||
expectedJson, | ||
objectMapper.writeValueAsString(new BadOuter(Data.of(inners))) | ||
); | ||
} | ||
} |