杰克逊无法在Android上加载JDK7类型 [英] Jackson unable to load JDK7 types on Android

查看:898
本文介绍了杰克逊无法在Android上加载JDK7类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Jackson 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:

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

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

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

推荐答案

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

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

这纯粹是杰克逊初始化此类问题时是否存在这些类 - 而且他们以某种组合存在。也许没关系,如果你不使用Java 7 java.nio.file.Path 类,那么你应该对这个记录的警告没有问题消息。因为这就是这个警告的内容,杰克逊支持这个特定类的序列化/反序列化。

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

查看 Android java.nio。* 软件包,它没有 java.nio.file。* 任何 API级别的软件包。这就解释了为什么你会看到警告信息。既然你不能使用 java.nio.file.Path ,除了讨厌的日志消息之外,这甚至都不是真正的问题。

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

如果此消息很麻烦,您可以随时为记录器 com.fasterxml.jackson.databind.ext.Java7Support 设置Java Util Logging级别。等级错误。然后,您将不会再看到这些警告消息。

If this message is bothersome you can always set the Java Util Logging level for logger com.fasterxml.jackson.databind.ext.Java7Support to be level ERROR. Then you will no longer see these warning messages.

有关已记录消息的详情:

在Jackson 2.8.x中,对Java 7类 java.nio.file.Path 的支持全部来自同一个JAR文件,是内置的。一个类动态检查另一个是否可以加载而不会出错:

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

Class<?> cls = Class.forName("com.fasterxml.jackson.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:


  • 运行时缺少一个或多个JDK 7类

  • com.fasterxml.jackson.databind.ext.Java7SupportImpl 在运行时丢失

  • one or more of the JDK 7 classes are missing at runtime
  • com.fasterxml.jackson.databind.ext.Java7SupportImpl is missing at runtime

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

Neither of those causes are Jackson'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.

参见:

  • Android import java.nio.file.Files; cannot be resolved
  • How to use java.nio.file package in android?
  • Android java.nio packages

这篇关于杰克逊无法在Android上加载JDK7类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆