Skip to content

Make some java platform modules optional #2913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.sql.Timestamp;
import java.text.*;
import java.util.*;

Expand All @@ -25,46 +24,47 @@
@SuppressWarnings("serial")
public class DateDeserializers
{
private final static HashSet<String> _classNames = new HashSet<String>();
private final static HashSet<String> _utilClasses = new HashSet<String>();

// classes from java.sql module, this module may not be present at runtime
private final static HashSet<String> _sqlClasses = new HashSet<String>();
static {
Class<?>[] numberTypes = new Class<?>[] {
Calendar.class,
GregorianCalendar.class,
java.sql.Date.class,
java.util.Date.class,
Timestamp.class,
};
for (Class<?> cls : numberTypes) {
_classNames.add(cls.getName());
}
_utilClasses.add("java.util.Calendar");
_utilClasses.add("java.util.GregorianCalendar");
_utilClasses.add("java.util.Date");

_sqlClasses.add("java.sql.Date");
_sqlClasses.add("java.sql.Timestamp");
}

public static JsonDeserializer<?> find(Class<?> rawType, String clsName)
{
if (_classNames.contains(clsName)) {
if (_utilClasses.contains(clsName)) {
// Start with the most common type
if (rawType == Calendar.class) {
if (rawType == java.util.Calendar.class) {
return new CalendarDeserializer();
}
if (rawType == java.util.Date.class) {
return DateDeserializer.instance;
}
if (rawType == java.util.GregorianCalendar.class) {
return new CalendarDeserializer(GregorianCalendar.class);
}
}
if (_sqlClasses.contains(clsName)) {
if (rawType == java.sql.Date.class) {
return new SqlDateDeserializer();
}
if (rawType == Timestamp.class) {
if (rawType == java.sql.Timestamp.class) {
return new TimestampDeserializer();
}
if (rawType == GregorianCalendar.class) {
return new CalendarDeserializer(GregorianCalendar.class);
}
}
return null;
}

// @since 2.11
public static boolean hasDeserializerFor(Class<?> rawType) {
return _classNames.contains(rawType.getName());
return _utilClasses.contains(rawType.getName()) || _sqlClasses.contains(rawType.getName());
}

/*
Expand Down Expand Up @@ -354,9 +354,9 @@ public java.sql.Date deserialize(JsonParser p, DeserializationContext ctxt) thro
* {@link DeserializationContext#parseDate} that this basic
* deserializer calls.
*/
public static class TimestampDeserializer extends DateBasedDeserializer<Timestamp>
public static class TimestampDeserializer extends DateBasedDeserializer<java.sql.Timestamp>
{
public TimestampDeserializer() { super(Timestamp.class); }
public TimestampDeserializer() { super(java.sql.Timestamp.class); }
public TimestampDeserializer(TimestampDeserializer src, DateFormat df, String formatString) {
super(src, df, formatString);
}
Expand All @@ -368,14 +368,14 @@ protected TimestampDeserializer withDateFormat(DateFormat df, String formatStrin

@Override // since 2.12
public Object getEmptyValue(DeserializationContext ctxt) {
return new Timestamp(0L);
return new java.sql.Timestamp(0L);
}

@Override
public java.sql.Timestamp deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
Date d = _parseDate(p, ctxt);
return (d == null) ? null : new Timestamp(d.getTime());
return (d == null) ? null : new java.sql.Timestamp(d.getTime());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public abstract class Java7Handlers
} 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");
// 02-Nov-2020, Xakep_SDK: Remove java.logging module dependency
// 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.fasterxml.jackson.databind.ext;

import java.util.logging.Logger;
import java.util.logging.Level;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.Deserializers;
import com.fasterxml.jackson.databind.ser.Serializers;
Expand Down Expand Up @@ -43,6 +40,8 @@ public class OptionalHandlerFactory implements java.io.Serializable
// // Since 2.7, we will assume DOM classes are always found, both due to JDK 1.6 minimum
// // and because Android (and presumably GAE) have these classes

// // 02-Nov-2020, Xakep_SDK: java.xml module classes may be missing
// // in actual runtime, if module java.xml is not present
private final static Class<?> CLASS_DOM_NODE;
private final static Class<?> CLASS_DOM_DOCUMENT;

Expand All @@ -53,8 +52,9 @@ public class OptionalHandlerFactory implements java.io.Serializable
doc = org.w3c.dom.Document.class;
} catch (Throwable e) {
// not optimal but will do
Logger.getLogger(OptionalHandlerFactory.class.getName())
.log(Level.INFO, "Could not load DOM `Node` and/or `Document` classes: no DOM support");
// 02-Nov-2020, Xakep_SDK: Remove java.logging module dependency
// Logger.getLogger(OptionalHandlerFactory.class.getName())
// .log(Level.INFO, "Could not load DOM `Node` and/or `Document` classes: no DOM support");
}
CLASS_DOM_NODE = node;
CLASS_DOM_DOCUMENT = doc;
Expand Down
11 changes: 7 additions & 4 deletions src/moditect/module-info.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Generated 08-Mar-2019 using Moditect maven plugin
module com.fasterxml.jackson.databind {
requires java.desktop;
requires java.logging;
// required for
// java.beans.ConstructorProperties
// java.beans.Transient
// support
requires static java.desktop;

requires transitive com.fasterxml.jackson.annotation;
requires transitive com.fasterxml.jackson.core;
// these types were suggested as transitive, but aren't actually
// exposed externally (only within internal APIs)
requires java.sql;
requires java.xml;
requires static java.sql;
requires static java.xml;

exports com.fasterxml.jackson.databind;
exports com.fasterxml.jackson.databind.annotation;
Expand Down