Skip to content

Commit c803a26

Browse files
mcasasolacowtowncoder
authored andcommitted
Fix #1872 (#1923)
1 parent 5d4eb51 commit c803a26

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

release-notes/VERSION

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.7.9.3 (not yet released)
8+
9+
#1872 `NullPointerException` in `SubTypeValidator.validateSubType` when
10+
validating Spring interface
11+
(reported by Rob W)
12+
713
2.7.9.2 (20-Dec-2017)
814

915
#1607: @JsonIdentityReference not used when setup on class only

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/SubTypeValidator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ public void validateSubType(DeserializationContext ctxt, JavaType type) throws J
7979

8080
// 18-Dec-2017, tatu: As per [databind#1855], need bit more sophisticated handling
8181
// for some Spring framework types
82-
if (full.startsWith(PREFIX_STRING)) {
83-
for (Class<?> cls = raw; cls != Object.class; cls = cls.getSuperclass()) {
82+
// 05-Jan-2017, tatu: ... also, only applies to classes, not interfaces
83+
if (!raw.isInterface() && full.startsWith(PREFIX_STRING)) {
84+
for (Class<?> cls = raw; (cls != null) && (cls != Object.class); cls = cls.getSuperclass()){
8485
String name = cls.getSimpleName();
8586
// looking for "AbstractBeanFactoryPointcutAdvisor" but no point to allow any is there?
8687
if ("AbstractPointcutAdvisor".equals(name)

src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import org.springframework.jacksontest.BogusApplicationContext;
44
import org.springframework.jacksontest.BogusPointcutAdvisor;
5+
import org.springframework.jacksontest.GrantedAuthority;
56

67
import com.fasterxml.jackson.annotation.JsonTypeInfo;
78
import com.fasterxml.jackson.databind.*;
89

10+
import java.util.ArrayList;
11+
import java.util.List;
12+
913
/**
1014
* Test case(s) to guard against handling of types that are illegal to handle
1115
* due to security constraints.
@@ -22,6 +26,10 @@ static class PolyWrapper {
2226
include = JsonTypeInfo.As.WRAPPER_ARRAY)
2327
public Object v;
2428
}
29+
30+
static class Authentication1872 {
31+
public List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
32+
}
2533

2634
/*
2735
/**********************************************************
@@ -30,7 +38,7 @@ static class PolyWrapper {
3038
*/
3139

3240
private final ObjectMapper MAPPER = objectMapper();
33-
41+
3442
// // // Tests for [databind#1599]
3543

3644
public void testXalanTypes1599() throws Exception
@@ -94,6 +102,17 @@ public void testC3P0Types1737() throws Exception
94102
}
95103
*/
96104

105+
// // // Tests for [databind#1872]
106+
public void testJDKTypes1872() throws Exception
107+
{
108+
ObjectMapper mapper = new ObjectMapper();
109+
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
110+
111+
String json = aposToQuotes(String.format("{'@class':'%s','authorities':['java.util.ArrayList',[]]}",
112+
Authentication1872.class.getName()));
113+
Authentication1872 result = mapper.readValue(json, Authentication1872.class);
114+
assertNotNull(result);
115+
}
97116
private void _testIllegalType(Class<?> nasty) throws Exception {
98117
_testIllegalType(nasty.getName());
99118
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.springframework.jacksontest;
2+
3+
public interface GrantedAuthority {
4+
5+
}

0 commit comments

Comments
 (0)