Skip to content

Commit 17a8c72

Browse files
committed
Merge branch '2.8'
2 parents 37461d6 + 3dd61ce commit 17a8c72

File tree

3 files changed

+142
-6
lines changed

3 files changed

+142
-6
lines changed

src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ public ArrayType constructArrayType(JavaType elementType) {
714714
* NOTE: type modifiers are NOT called on Collection type itself; but are called
715715
* for contained types.
716716
*/
717-
public CollectionType constructCollectionType(Class<? extends Collection> collectionClass, Class<?> elementClass) {
717+
public CollectionType constructCollectionType(Class<? extends Collection> collectionClass,
718+
Class<?> elementClass) {
718719
return constructCollectionType(collectionClass,
719720
_fromClass(null, elementClass, EMPTY_BINDINGS));
720721
}
@@ -725,7 +726,8 @@ public CollectionType constructCollectionType(Class<? extends Collection> collec
725726
* NOTE: type modifiers are NOT called on Collection type itself; but are called
726727
* for contained types.
727728
*/
728-
public CollectionType constructCollectionType(Class<? extends Collection> collectionClass, JavaType elementType) {
729+
public CollectionType constructCollectionType(Class<? extends Collection> collectionClass,
730+
JavaType elementType) {
729731
// 19-Oct-2015, tatu: Allow case of no-type-variables, since it seems likely to be
730732
// a valid use case here
731733
return (CollectionType) _fromClass(null, collectionClass,
@@ -764,7 +766,8 @@ public CollectionLikeType constructCollectionLikeType(Class<?> collectionClass,
764766
* NOTE: type modifiers are NOT called on constructed type itself; but are called
765767
* for contained types.
766768
*/
767-
public MapType constructMapType(Class<? extends Map> mapClass, Class<?> keyClass, Class<?> valueClass) {
769+
public MapType constructMapType(Class<? extends Map> mapClass,
770+
Class<?> keyClass, Class<?> valueClass) {
768771
JavaType kt, vt;
769772
if (mapClass == Properties.class) {
770773
kt = vt = CORE_TYPE_STRING;
@@ -783,9 +786,7 @@ public MapType constructMapType(Class<? extends Map> mapClass, Class<?> keyClass
783786
*/
784787
public MapType constructMapType(Class<? extends Map> mapClass, JavaType keyType, JavaType valueType) {
785788
return (MapType) _fromClass(null, mapClass,
786-
TypeBindings.create(mapClass, new JavaType[] {
787-
keyType, valueType
788-
}));
789+
TypeBindings.create(mapClass, keyType, valueType));
789790
}
790791

791792
/**
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.List;
4+
import java.util.UUID;
5+
6+
import com.fasterxml.jackson.annotation.*;
7+
8+
import com.fasterxml.jackson.databind.BaseMapTest;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
11+
public class BackReference1516Test extends BaseMapTest
12+
{
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
static class ParentObject {
15+
public UUID id;
16+
public String productId;
17+
public String productName;
18+
public String companyName;
19+
public UUID companyLogoImageId;
20+
public String recordNumber;
21+
public String revisionNumber;
22+
public String jsonString;
23+
24+
// Test passes if @JsonManagedReference is removed.
25+
@JsonManagedReference
26+
public List<ChildObject> childSet;
27+
28+
public ParentObject() { }
29+
}
30+
31+
@JsonIgnoreProperties(ignoreUnknown = true)
32+
static class ChildObject
33+
{
34+
public UUID id;
35+
// Test passes if @JsonBackReference is removed.
36+
@JsonBackReference
37+
public ParentObject parentObject;
38+
public UUID componentId;
39+
public int orderNumber;
40+
public String orderLabel;
41+
public String title;
42+
43+
public ChildObject() { }
44+
}
45+
46+
/*
47+
/**********************************************************
48+
/* Unit tests
49+
/**********************************************************
50+
*/
51+
52+
private final ObjectMapper MAPPER = new ObjectMapper();
53+
54+
public void testIssue1516() throws Exception
55+
{
56+
ParentObject result = MAPPER.readValue(aposToQuotes(
57+
"{\n"+
58+
" 'companyName': 'My Famke Company',\n"+
59+
" 'companyLogoImageId': '29a8045e-3d10-4121-9f27-429aa74d00ad',\n"+
60+
" 'productId': 'ABC-0003',\n"+
61+
" 'productName': 'Engineering Test',\n"+
62+
" 'recordNumber': '01',\n"+
63+
" 'revisionNumber': '1.0',\n"+
64+
" 'procedureId': '6e6f607e-fb3f-4750-8a0a-2b38220e3328',\n"+
65+
" 'childSet': [ { 'title': 'Child 1',\n"+
66+
" 'componentId': '3f7debe1-cddc-4b66-b7a7-49249e0c9d3e',\n"+
67+
" 'orderLabel': '1',\n"+
68+
" 'orderNumber': 1\n"+
69+
" } ]\n"+
70+
"}"),
71+
ParentObject.class);
72+
assertNotNull(result);
73+
}
74+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.databind.BaseMapTest;
6+
import com.fasterxml.jackson.databind.JavaType;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.databind.type.CollectionType;
9+
import com.fasterxml.jackson.databind.type.MapType;
10+
11+
// for [databind#1415]
12+
public class CollectionType1415Test extends BaseMapTest
13+
{
14+
static abstract class LongList implements List<Long> { }
15+
16+
static abstract class StringLongMap implements Map<String,Long> { }
17+
18+
/*
19+
/**********************************************************
20+
/* Unit tests
21+
/**********************************************************
22+
*/
23+
24+
private final ObjectMapper MAPPER = new ObjectMapper();
25+
26+
public void testExplicitCollectionType() throws Exception
27+
{
28+
JavaType t = MAPPER.getTypeFactory()
29+
.constructCollectionType(LongList.class, Long.class);
30+
assertEquals(LongList.class, t.getRawClass());
31+
assertEquals(Long.class, t.getContentType().getRawClass());
32+
}
33+
34+
public void testImplicitCollectionType() throws Exception
35+
{
36+
JavaType t = MAPPER.getTypeFactory()
37+
.constructParametricType(List.class, Long.class);
38+
assertEquals(CollectionType.class, t.getClass());
39+
assertEquals(List.class, t.getRawClass());
40+
assertEquals(Long.class, t.getContentType().getRawClass());
41+
}
42+
43+
public void testExplicitMapType() throws Exception
44+
{
45+
JavaType t = MAPPER.getTypeFactory()
46+
.constructMapType(StringLongMap.class,
47+
String.class, Long.class);
48+
assertEquals(StringLongMap.class, t.getRawClass());
49+
assertEquals(String.class, t.getKeyType().getRawClass());
50+
assertEquals(Long.class, t.getContentType().getRawClass());
51+
}
52+
53+
public void testImplicitMapType() throws Exception
54+
{
55+
JavaType t = MAPPER.getTypeFactory()
56+
.constructParametricType(Map.class, Long.class, Boolean.class);
57+
assertEquals(MapType.class, t.getClass());
58+
assertEquals(Long.class, t.getKeyType().getRawClass());
59+
assertEquals(Boolean.class, t.getContentType().getRawClass());
60+
}
61+
}

0 commit comments

Comments
 (0)