|
21 | 21 |
|
22 | 22 | import androidx.annotation.Keep;
|
23 | 23 | import com.google.firebase.database.core.utilities.encoding.CustomClassMapper;
|
| 24 | +import java.io.Serializable; |
24 | 25 | import java.util.ArrayList;
|
25 | 26 | import java.util.Arrays;
|
26 | 27 | import java.util.Collection;
|
@@ -628,6 +629,22 @@ public String getValue() {
|
628 | 629 | }
|
629 | 630 | }
|
630 | 631 |
|
| 632 | + private static class MultiBoundedMapBean<T extends String & Serializable> { |
| 633 | + private Map<String, T> values; |
| 634 | + |
| 635 | + public Map<String, T> getValues() { |
| 636 | + return values; |
| 637 | + } |
| 638 | + } |
| 639 | + |
| 640 | + private static class MultiBoundedMapHolderBean { |
| 641 | + private MultiBoundedMapBean<String> map; |
| 642 | + |
| 643 | + public MultiBoundedMapBean<String> getMap() { |
| 644 | + return map; |
| 645 | + } |
| 646 | + } |
| 647 | + |
631 | 648 | private static class StaticFieldBean {
|
632 | 649 | public static String value1 = "static-value";
|
633 | 650 | public String value2;
|
@@ -1772,6 +1789,24 @@ public void usingWildcardInGenericTypeIndicatorIsAllowed() {
|
1772 | 1789 | fooMap, new GenericTypeIndicator<Map<String, ? extends String>>() {}));
|
1773 | 1790 | }
|
1774 | 1791 |
|
| 1792 | + @Test(expected = DatabaseException.class) |
| 1793 | + public void usingLowerBoundWildcardsIsForbidden() { |
| 1794 | + Map<String, String> fooMap = Collections.singletonMap("foo", "bar"); |
| 1795 | + CustomClassMapper.convertToCustomClass( |
| 1796 | + fooMap, new GenericTypeIndicator<Map<String, ? super String>>() {}); |
| 1797 | + } |
| 1798 | + |
| 1799 | + @Test |
| 1800 | + public void multiBoundedWildcardsUsesTheFirst() { |
| 1801 | + Map<String, Object> source = |
| 1802 | + Collections.singletonMap( |
| 1803 | + "map", Collections.singletonMap("values", Collections.singletonMap("foo", "bar"))); |
| 1804 | + MultiBoundedMapHolderBean bean = |
| 1805 | + CustomClassMapper.convertToCustomClass(source, MultiBoundedMapHolderBean.class); |
| 1806 | + Map<String, String> expected = Collections.singletonMap("foo", "bar"); |
| 1807 | + assertEquals(expected, bean.map.values); |
| 1808 | + } |
| 1809 | + |
1775 | 1810 | @Test(expected = DatabaseException.class)
|
1776 | 1811 | public void unknownTypeParametersNotSupported() {
|
1777 | 1812 | deserialize("{'value': 'foo'}", new GenericTypeIndicatorSubclass<GenericBean<?>>() {});
|
|
0 commit comments