JSR310Module无法实例化

时间:2016-12-23 20:30:12

标签: jackson

我有一个简单的程序将JSON对象反序列化为Java Class,我使用的是Jackson库。我收到以下错误?请指教。感谢。

示例应用程序可在https://github.com/Manjesh80/question

找到
Exception in thread "main" java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.datatype.jsr310.JSR310Module could not be instantiated
        at java.util.ServiceLoader.fail(ServiceLoader.java:232)
        at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
    Caused by: java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JSR310Module

该计划

import com.fasterxml.jackson.databind.DeserializationFeature;
    import com.fasterxml.jackson.databind.ObjectMapper;

    import java.io.IOException;
    import java.time.OffsetDateTime;


    public class JacksonGenericDataBinding {

        public static void main(String[] args) throws IOException {
            JacksonGenericDataBinding jacksonGenericDataBinding = new JacksonGenericDataBinding();
            jacksonGenericDataBinding.deserializeEvent();
        }

        public void deserializeEvent() throws IOException {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.findAndRegisterModules();


            Event event = objectMapper.readValue(getClass().getResourceAsStream("/event.json"), Event.class);
            System.out.println("Event ID ==>" + event.getDeviceID());
        }
    }

event.json

{     &#34; deviceID&#34;:&#34; Ethernet&#34;,     &#34; networkID&#34;:&#34; Net-01&#34;,     &#34; eventTime&#34;:&#34; 2011-12-03T10:15:30 + 01:00&#34;   }

1 个答案:

答案 0 :(得分:0)

当我同时使用Jasper 6.1.0和Azure Blob存储时,我遇到了类似的问题。两者都添加了两个版本的Jackson依赖项。 例如

  1. Jasper正在添加Jackson 2.1
  2. Azure Blob正在添加Jackson 2.8

要解决此问题,只需从Jasper中排除旧版本,现在它就可以正常工作