Skip to content

Commit 755e3bc

Browse files
committed
Fix #1872
1 parent d9bbae4 commit 755e3bc

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<groupId>com.fasterxml.jackson.core</groupId>
1212
<artifactId>jackson-databind</artifactId>
13-
<version>2.8.12-SNAPSHOT</version>
13+
<version>2.8.11.1-SNAPSHOT</version>
1414
<name>jackson-databind</name>
1515
<packaging>bundle</packaging>
1616
<description>General data-binding functionality for Jackson: works on core streaming API</description>

release-notes/VERSION

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Project: jackson-databind
33
=== Releases ===
44
------------------------------------------------------------------------
55

6+
2.8.11.1 (not yet released)
7+
8+
#1872 `NullPointerException` in `SubTypeValidator.validateSubType` when
9+
validating Spring interface
10+
(reported by Rob W)
11+
612
2.8.11 (24-Dec-2017)
713

814
#1604: Nested type arguments doesn't work with polymorphic types

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.fasterxml.jackson.databind.introspect.*;
1414
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
1515
import com.fasterxml.jackson.databind.jsontype.impl.SubTypeValidator;
16-
import com.fasterxml.jackson.databind.util.ArrayBuilders;
1716
import com.fasterxml.jackson.databind.util.ClassUtil;
1817
import com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition;
1918

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

+3-2
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

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.fasterxml.jackson.databind.interop;
22

3+
import java.util.*;
4+
35
import org.springframework.jacksontest.BogusApplicationContext;
46
import org.springframework.jacksontest.BogusPointcutAdvisor;
7+
import org.springframework.jacksontest.GrantedAuthority;
58

69
import com.fasterxml.jackson.annotation.JsonTypeInfo;
710
import com.fasterxml.jackson.databind.*;
@@ -22,7 +25,11 @@ static class PolyWrapper {
2225
include = JsonTypeInfo.As.WRAPPER_ARRAY)
2326
public Object v;
2427
}
25-
28+
29+
static class Authentication1872 {
30+
public List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
31+
}
32+
2633
/*
2734
/**********************************************************
2835
/* Unit tests
@@ -94,6 +101,18 @@ public void testC3P0Types1737() throws Exception
94101
}
95102
*/
96103

104+
// // // Tests for [databind#1872]
105+
public void testJDKTypes1872() throws Exception
106+
{
107+
ObjectMapper mapper = new ObjectMapper();
108+
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
109+
110+
String json = aposToQuotes(String.format("{'@class':'%s','authorities':['java.util.ArrayList',[]]}",
111+
Authentication1872.class.getName()));
112+
Authentication1872 result = mapper.readValue(json, Authentication1872.class);
113+
assertNotNull(result);
114+
}
115+
97116
private void _testIllegalType(Class<?> nasty) throws Exception {
98117
_testIllegalType(nasty.getName());
99118
}
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)