Skip to content

Commit

Permalink
Fix #2446
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 10, 2019
1 parent 9ce3d1c commit 052be02
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 42 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -930,3 +930,8 @@ Hesham Massoud (heshamMassoud@github)
* Reported, contributed fix for #2442: `ArrayNode.addAll()` adds raw `null` values
which cause NPE on `deepCopy()`
(2.10.0)
David Connelly (dconnelly@github)
* Reported#2446: Java 11: Unable to load JDK7 types (annotations, java.nio.file.Path):
no Java7 support added
(2.10.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project: jackson-databind
#2442: `ArrayNode.addAll()` adds raw `null` values which cause NPE on `deepCopy()`
and `toString()`
(reported, fix contributed by Hesham M)
#2446: Java 11: Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added
(reported by David C)
2.10.0.pr1 (19-Jul-2019)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.fasterxml.jackson.databind.ext;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.util.ClassUtil;

/**
* To support Java7-incomplete platforms, we will offer support for JDK 7
* datatype(s) (that is, {@link java.nio.file.Path} through this class, loaded
* dynamically; if loading fails, support will be missing.
* This class is the non-JDK-7-dependent API, and {@link Java7HandlersImpl} is
* JDK7-dependent implementation of functionality.
*
* @since 2.10 (cleaved off of {@link Java7Support})
*/
public abstract class Java7Handlers
{
private final static Java7Handlers IMPL;

static {
Java7Handlers impl = null;
try {
Class<?> cls = Class.forName("com.fasterxml.jackson.databind.ext.Java7HandlersImpl");
impl = (Java7Handlers) ClassUtil.createInstance(cls, false);
} catch (Throwable t) {
// 09-Sep-2019, tatu: Could choose not to log this, but since this is less likely
// to miss (than annotations), do it
java.util.logging.Logger.getLogger(Java7Handlers.class.getName())
.warning("Unable to load JDK7 types (java.nio.file.Path): no Java7 type support added");
}
IMPL = impl;
}

public static Java7Handlers instance() {
return IMPL;
}

public abstract Class<?> getClassJavaNioFilePath();

public abstract JsonDeserializer<?> getDeserializerForJavaNioFilePath(Class<?> rawType);

public abstract JsonSerializer<?> getSerializerForJavaNioFilePath(Class<?> rawType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.fasterxml.jackson.databind.ext;

import java.nio.file.Path;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;

/**
* @since 2.10
*/
public class Java7HandlersImpl extends Java7Handlers
{
@Override
public Class<?> getClassJavaNioFilePath() {
return Path.class;
}

@Override
public JsonDeserializer<?> getDeserializerForJavaNioFilePath(Class<?> rawType) {
if (rawType == Path.class) {
return new NioPathDeserializer();
}
return null;
}

@Override
public JsonSerializer<?> getSerializerForJavaNioFilePath(Class<?> rawType) {
if (Path.class.isAssignableFrom(rawType)) {
return new NioPathSerializer();
}
return null;
}
}
16 changes: 4 additions & 12 deletions src/main/java/com/fasterxml/jackson/databind/ext/Java7Support.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.fasterxml.jackson.databind.ext;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
Expand All @@ -17,16 +15,16 @@
public abstract class Java7Support
{
private final static Java7Support IMPL;

static {
Java7Support impl = null;
try {
Class<?> cls = Class.forName("com.fasterxml.jackson.databind.ext.Java7SupportImpl");
impl = (Java7Support) ClassUtil.createInstance(cls, false);
} catch (Throwable t) {
// 24-Nov-2015, tatu: Should we log or not?
java.util.logging.Logger.getLogger(Java7Support.class.getName())
.warning("Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added");
// 09-Sep-2019, tatu: Used to log earlier, but with 2.10.0 let's not log
// java.util.logging.Logger.getLogger(Java7Support.class.getName())
// .warning("Unable to load JDK7 annotations (@ConstructorProperties, @Transient): no Java7 annotation support added");
}
IMPL = impl;
}
Expand All @@ -40,10 +38,4 @@ public static Java7Support instance() {
public abstract Boolean hasCreatorAnnotation(Annotated a);

public abstract PropertyName findConstructorName(AnnotatedParameter p);

public abstract Class<?> getClassJavaNioFilePath();

public abstract JsonDeserializer<?> getDeserializerForJavaNioFilePath(Class<?> rawType);

public abstract JsonSerializer<?> getSerializerForJavaNioFilePath(Class<?> rawType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.beans.ConstructorProperties;
import java.beans.Transient;
import java.nio.file.Path;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
Expand All @@ -26,27 +23,6 @@ public Java7SupportImpl() {
_bogus = cls;
}

@Override
public Class<?> getClassJavaNioFilePath() {
return Path.class;
}

@Override
public JsonDeserializer<?> getDeserializerForJavaNioFilePath(Class<?> rawType) {
if (rawType == Path.class) {
return new NioPathDeserializer();
}
return null;
}

@Override
public JsonSerializer<?> getSerializerForJavaNioFilePath(Class<?> rawType) {
if (Path.class.isAssignableFrom(rawType)) {
return new NioPathSerializer();
}
return null;
}

@Override
public Boolean findTransient(Annotated a) {
Transient t = a.getAnnotation(Transient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public class OptionalHandlerFactory implements java.io.Serializable
// // (note: also assume it comes from JDK so that ClassLoader issues with OSGi
// // can, I hope, be avoided?)

private static final Java7Support _jdk7Helper;
private static final Java7Handlers _jdk7Helper;
static {
Java7Support x = null;
Java7Handlers x = null;
try {
x = Java7Support.instance();
x = Java7Handlers.instance();
} catch (Throwable t) { }
_jdk7Helper = x;
}
Expand All @@ -88,15 +88,17 @@ public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType typ
{
final Class<?> rawType = type.getRawClass();

if ((CLASS_DOM_NODE != null) && CLASS_DOM_NODE.isAssignableFrom(rawType)) {
return (JsonSerializer<?>) instantiate(SERIALIZER_FOR_DOM_NODE);
}

if (_jdk7Helper != null) {
JsonSerializer<?> ser = _jdk7Helper.getSerializerForJavaNioFilePath(rawType);
if (ser != null) {
return ser;
}
}
if ((CLASS_DOM_NODE != null) && CLASS_DOM_NODE.isAssignableFrom(rawType)) {
return (JsonSerializer<?>) instantiate(SERIALIZER_FOR_DOM_NODE);
}

String className = rawType.getName();
String factoryName;
if (className.startsWith(PACKAGE_PREFIX_JAVAX_XML) || hasSuperClassStartingWith(rawType, PACKAGE_PREFIX_JAVAX_XML)) {
Expand Down

0 comments on commit 052be02

Please sign in to comment.