Search code examples
javajsonapache-pighadoop2jsonpath

JSON Path 2.3.0 conflicts with hadoop 2.7 Environment JSON-smart1.2.0.jar


  1. Have a Input of JSON inside HDFS location
  2. It is required to parse the JSON and to aggregate results
  3. To do am using the PIG UDF which are using JSON-path libraries
  4. On the hadoop2.7 environment jar: json-smart1.2, json-path1.2 are hardbinded
  5. Whenever I execute the PIG Mapreduce which throws me below Exception

    java.lang.NoSuchFieldError: defaultReader
    at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
    at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
    at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:174)
    at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52)
    at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
    

In-order to solve the problem tried below options

Option 1: Tried setting Registering the json-smart2.3.jar & json-path2.3.0.jar But no promising results (As the Jar it was referencing is json-path1.2.jar)

Option 2: Downgrading my module dependencies to json-path1.2.jar No results

Option 3: Using Custom classLoaders tried to load the jar of JSON-path2.3.0 jar it loaded the class went into issues of Org.slf4j binding

There were multiple binding paths identified, But went problems with sun.misc classloader

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NullPointerException
    at sun.net.util.URLUtil.urlNoFragString(URLUtil.java:50)
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:485)
    at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
    at sun.misc.URLClassPath.access$100(URLClassPath.java:64)
    at sun.misc.URLClassPath$1.next(URLClassPath.java:239)
    at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:250)
    at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
    at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
    at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
    at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
    at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
    at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:238)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:138)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
    at com.jayway.jsonpath.internal.JsonContext.<clinit>(JsonContext.java:41)
    at com.jayway.jsonpath.internal.ParseContextImpl.parse(ParseContextImpl.java:38)
    at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:599)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.optum.pdm.ReferenceDataUpdate.addURL(ReferenceDataUpdate.java:112)
    at com.optum.pdm.ReferenceDataUpdate.main(ReferenceDataUpdate.java:124)
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.optum.pdm.ReferenceDataUpdate.addURL(ReferenceDataUpdate.java:112)
    at com.optum.pdm.ReferenceDataUpdate.main(ReferenceDataUpdate.java:124)
Caused by: java.lang.ExceptionInInitializerError
    at com.jayway.jsonpath.internal.ParseContextImpl.parse(ParseContextImpl.java:38)
    at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:599)
    ... 6 more
Caused by: java.lang.IllegalStateException: Unexpected initialization failure
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:167)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
    at com.jayway.jsonpath.internal.JsonContext.<clinit>(JsonContext.java:41)
    ... 8 more
Caused by: java.lang.NullPointerException
    at sun.net.util.URLUtil.urlNoFragString(URLUtil.java:50)
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:485)
    at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
    at sun.misc.URLClassPath.access$100(URLClassPath.java:64)
    at sun.misc.URLClassPath$1.next(URLClassPath.java:239)
    at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:250)
    at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
    at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
    at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
    at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
    at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
    at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:238)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:138)
    ... 13 more

Can some one suggest me to solve this problem, Can find one stackoverflow link where it was telling about weblogic and not a generalized solution which can be applied on Hadoop2.7 also (JSON Parser -java.lang.NoSuchFieldError: defaultReader)


Solution

  • Provide the custom implementation to load/parse the JSON so that we can avoid using Json-smart-2.x/1.x of Hadoop/lib

      public static void changeJsonPathConfig() {
    
        if (!configChanged) {
    
            Configuration.setDefaults(new Configuration.Defaults() {
    
    
    
                private final JsonProvider jsonProvider = new GsonJsonProvider(
    
                        new GsonBuilder().serializeNulls().create());
    
                private final MappingProvider mappingProvider = new GsonMappingProvider();
    
    
    
                @Override
    
                public JsonProvider jsonProvider() {
    
                    return jsonProvider;
    
                }
    
    
    
                @Override
    
                public MappingProvider mappingProvider() {
    
                    return mappingProvider;
    
                }
    
    
    
                @Override
    
                public Set<Option> options() {
    
                    return EnumSet.noneOf(Option.class);
    
                }
    
            });
    
            configChanged = true;
    
        }
    
    }