java Jackson 无法在 Android 上加载 JDK7 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39425594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:22:02  来源:igfitidea点击:

Hymanson unable to load JDK7 types on Android

javaandroidHymansonjava-7kotlin

提问by tyrondis

I use Hymanson 2.8.2 in my Android app to deserialize JSON. The deserialization itself works, however, I can see the following warning in the application log:

我在我的 Android 应用程序中使用 Hymanson 2.8.2 来反序列化 JSON。反序列化本身有效,但是,我可以在应用程序日志中看到以下警告:

Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added

Proguard is disabled, sourceCompatibilityis set to '1.7'. How can I add these seemingly missing types to my build?

Proguard 被禁用,sourceCompatibility设置为'1.7'. 如何将这些看似缺失的类型添加到我的构建中?

回答by Jayson Minard

First, your sourceCompatibilitysetting of 1.7doesn't mean anything about the runtime environment, so it has no impact on this message.

首先,您的sourceCompatibility设置对1.7运行时环境没有任何意义,因此它对此消息没有影响。

This is purely a "do these classes exist at the time Hymanson initializes this class" issue -- and they do notexist in some combination. And maybe that is ok, if you do not use the Java 7 java.nio.file.Pathclass then you should have no issue with this logged warningmessage. Because that is what this warning is about, Hymanson supporting serialization/deserialization of this specific class.

这纯粹是一个“在 Hymanson 初始化这个类时这些类是否存在”的问题——并且它们以某种组合存在。也许这java.nio.file.Path没问题,如果您不使用 Java 7类,那么此记录的警告消息应该没有问题。因为这就是这个警告的内容,Hyman逊支持这个特定类的序列化/反序列化。

Looking at Android java.nio.*packages, it does not have java.nio.file.*packages at anyAPI level. So that explains why you see the warning message. And since you can't use java.nio.file.Pathanyway, this isn't even a real issue other than an annoying logging message.

查看Androidjava.nio.*,它没有任何API 级别的java.nio.file.*包。这解释了为什么您会看到警告消息。而且由于您无论如何都无法使用,因此除了烦人的日志消息之外,这甚至不是一个真正的问题。java.nio.file.Path

If this message is bothersome you can always set the Java Util Logging level for logger com.fasterxml.Hymanson.databind.ext.Java7Supportto be level ERROR. Then you will no longer see these warningmessages.

如果此消息很烦人,您始终可以将 logger 的 Java Util Logging 级别设置为com.fasterxml.Hymanson.databind.ext.Java7Supportlevel ERROR。然后您将不再看到这些警告消息。

More about the logged message:

有关记录的消息的更多信息:

In Hymanson 2.8.x this support for Java 7 class java.nio.file.Pathis all loading from the same JAR file and is built-in. One class dynamically checks if another can load without error:

在 Hymanson 2.8.x 中,对 Java 7 类的这种支持java.nio.file.Path都是从同一个 JAR 文件加载的,并且是内置的。一个类动态检查另一个类是否可以正确加载:

Class<?> cls = Class.forName("com.fasterxml.Hymanson.databind.ext.Java7SupportImpl");

The only way this can fail is if something is stripping this class from the final set of classes. Or one of these classes it depends on is missing from the runtime:

这可能失败的唯一方法是,如果有什么东西从最终的类集中剥离了这个类。或者它所依赖的这些类之一在运行时中丢失了:

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

If any of those are missing then you will see the logged error message. So one of these is true:

如果缺少其中任何一个,那么您将看到记录的错误消息。所以其中之一是正确的:

  • one or more of the JDK 7 classes are missing at runtime
  • com.fasterxml.Hymanson.databind.ext.Java7SupportImplis missing at runtime
  • 运行时缺少一个或多个 JDK 7 类
  • com.fasterxml.Hymanson.databind.ext.Java7SupportImpl运行时丢失

Neither of those causes are Hymanson's fault, they are something about your runtime environment (i.e. they don't exist in Android API's), or Proguard stripping classes it doesn't think are used.

这些原因都不是 Hymanson 的错,它们与您的运行时环境有关(即它们不存在于 Android API 中),或者它认为没有使用的 Proguard 剥离类。

See also:

也可以看看: