Object Mapper - YAMLFactory - exception due to missing _createContentReference method - java

I'm using the latest 2.13.0 version of jackson, and when I try to parse a YAML file, I'm getting this exception
java.lang.NoSuchMethodError: 'com.fasterxml.jackson.core.io.ContentReference com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createContentReference(java.lang.Object)'
What could be the issue?
The dependencies that I've included are jackson-core, jackson-databind and jackson-dataformat-yaml - all 2.13.0

No such method error in most cases means that you have have 2 dependencies that are the same but with different versions, however the application is loading the version that does not have this method in it,
The reference to this _createContentReference exists in YAMLFactory in jackson-dataformat-yaml.jar
The actual _createContentReference implementation exists in com.fasterxml.jackson.core.JsonFactory which exists jackson-core.2.13.0.
In your case, you probably have another jackson-core.jar with an older version as part of your indirect dependencies.
You can see mvn dependency:tree or your IDE (Such as Eclipse allows you to search for dependency by name, and it returns all that match, including their versions)

Thanks.
It helped me to exclude jackson-dataformat-yaml version 2.13.1 from quarkus-smallrye-openapi and include 2.12.3 . Like this :
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.12.3</version>
</dependency>

The same problem I also faced. My environment is -
Wildfly version - 26.1.1-Final
Spring boot - 2.7.8
The issue is coming because Wildfly has the same version API already added as module and the same set of jackson* series jars are going thourgh spring boot hence on runtime it is creating issue.
Solution - all jackson* jar under spring-boot pom.xml add into exclusion list and separtly added dependencies with scope provied. My modified pom.xml is as below -
<properties>
<spring.boot.version>2.7.8</spring.boot.version>
<jackson.version>2.13.4</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<!-- Exclusion list -->
<exclusion>
<artifactId>jackson-datatype-jdk8</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- added dependency with provided scope -->
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>jackson-datatype-jdk8</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

Related

Override elasticsearch-rest-high-level-client version in spring boot

I need to override a library version from a spring boot starter.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
This dependency spring-boot-starter-data-elasticsearch uses:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>4.3.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>transport</artifactId>
<groupId>org.elasticsearch.client</groupId>
</exclusion>
</exclusions>
</dependency>
And this dependency spring-data-elasticsearch uses
<properties>
<elasticsearch>7.15.2</elasticsearch>
...
</properties>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>${elasticsearch}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
I added a new version to my pom's properties
<properties>
...
<elasticsearch>7.13.4</elasticsearch>
</properties>
But I still have 7.15.2 version

How to override pom.xml dependency over liberty dependency mentioned in server.xml at deployment time?

I am facing issue related to old version of dependency jpa2.0 mentioned in liberty server.xml file.
I want to use project's pom.xml hibernate-jpa-2.1-api dependency without removing liberty's jpa 2.0 (com.ibm.websphere.javaee.persistence.2.0_1.0.53.jar) dependency.
Error while deploying in liberty SIT environment:
Caused by: java.lang.NoSuchMethodError: javax/persistence/JoinColumn.foreignKey()Ljavax/persistence/ForeignKey; (loaded from file:/apps/waslb/sit/shared/websupporta/wlp/lib/../dev/api/spec/com.ibm.websphere.javaee.persistence.2.0_1.0.53.jar by org.eclipse.osgi.internal.loader.EquinoxClassLoader#69b35caa[com.ibm.websphere.javaee.persistence.2.0:1.0.53.cl210620210527-1900(id=117)]) called from class org.hibernate.cfg.AnnotationBinder (loaded from file:/apps/waslb/sit/shared/websupporta/wlp/usr/servers/websupporta11/apps/expanded/web-apps-esignservices-war.war/WEB-INF/lib/hibernate-core-4.3.11.Final.jar by com.ibm.ws.classloading.internal.AppClassLoader#40ad1256).
Below is the pom.xml file dependencies:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre8</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.2.0.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
Method JoinColumn.foreignKey() was added in JPA2.2 library onwards, So below JPA2.2 version it's not available.
Issue resolved, After removing support of above method and dependencies version updated as mention below as hibernate version 4.2.15 is compatible with JPA 2.1
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.15.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.15.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>

CXF ClassNotFoundException: javax.ws.rs.MessageProcessingException

I'm trying to start a jax ws & rs server endpoints, I can get them started using rs-api 2.0 (and version 2.0.1) but when I try to make a request it throws
java.lang.NoClassDefFoundError: javax/ws/rs/MessageProcessingException
There are some other threads in SO regarding this matter but the suggestions don't work for me. Using any of the rs-api 2 milestone versions throws issues
Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/BadRequestException
I'm running this as a java application, not a webapp. Anyone have any ideas to try? Thanks
EDIT: My dependencies. I added jsr311 but that did not change the MessageProcessingException
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
CXF: version 2.7.0
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
</dependency>
rs-api version: 2.0
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
jsr311 version: 1.1.1
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
Faced the same issue, but later when I used 3.0.0-milestone2 of cxf-bundle with 2.1-m01 of javax.ws.rs-api, it worked like a charm.
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1-m01</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>3.0.0-milestone2</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m10</version>
</dependency>
This version has support for javax.ws.rs.MessageProcessingException class.
I took this same error using Jersey client without JSON/JAXB providers to do the calls to server, when I configure Jettison provider the problem was solved. This erros also occour when I use a incompatible POJO to marshaling object to call service. check it. I hope this help.
The problem also occur when you have Classloader problems, check your maven dependecy hierarchy conflicts of jax-rs. In my case I need to use exlcusion filter in my pom.xml like
<exclusions>
<exclusion>
<artifactId>javax.ws.rs-api</artifactId>
<groupId>javax.ws.rs</groupId>
</exclusion>
</exclusions>
I made exclusion in cxf-bundle-jaxrs in another project that uses javax.ws.rs-api dependency. Using dependency of cxf-rt-frontend-jaxrs:2.7.11 was sufficient.
I had the same issue & I had to add this exclusion -
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</exclusion>

Exclude a maven dependecie from a derived pom

I'm using Apache Maven 3.1.1
In my parent pom there is a dependencie defined as follows:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2_09</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
The issue is I don't want to include that dependencie in one of my derived poms. I tried the following:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<exclusions>
<exclusion>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.6</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
But I got both jsf-impl-1.2_09.jar and jsf-impl-2.0.6.jar jars instead of jsf-impl-2.0.6.jar only. Is there a way to fix that?

What is correct version or jackson for spring?

I am using jackson converter (MappingJacksonHttpMessageConverter) to consume and produce json data from spring controller. But while invoking controller throws following exception.
Caused by: java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.isConcrete()Z
at org.codehaus.jackson.map.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:80)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:266)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCacheValueDeserializer(StdDeserializerProvider.java:198)
at org.codehaus.jackson.map.deser.StdDeserializerProvider.hasValueDeserializerFor(StdDeserializerProvider.java:152)
at org.codehaus.jackson.map.ObjectMapper.canDeserialize(ObjectMapper.java:829)
My code:
Spring bean file:
abc.CartType
abc.CartResponseType
pom file (snippets only)
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compileSource>1.5</compileSource>
<org.springframework.version>3.0.2.RELEASE</org.springframework.version>
<jboss.server.name>network-epro</jboss.server.name>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>sso</groupId>
<artifactId>casclient</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.1.5.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib-ext-spring</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>xpp</groupId>
<artifactId>xpp</artifactId>
<version>2.3.0</version>
</dependency>
<!-- http://code.google.com/p/jsonp-java/ -->
<dependency>
<groupId>org.jsonp</groupId>
<artifactId>jsonp</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>email</groupId>
<artifactId>email-client</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.2.ga</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!--
Jboss client dependancy.
-->
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.2.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-oxm-tiger</artifactId>
<version>1.5.9</version>
</dependency>
I can see in spring-web pom file jackson version is mentioned as 1.4.2 and same I have used still it is throwing exception regarding method not found. Am I using correct version?
You seem to be missing the jackson-core dependency. You need that as well as jackson-mapper.
The 1.4.x version should be fine, although it shouldn't hurt to upgrade it to something more recent.
I think you have differing versions between Jackson core and mapper jars (former has streaming parser/generator; latter data binding). It is hard to ensure that transitive dependencies have compatible versions -- while multiple Jackson versions work just fine with Spring (and most other frameworks), versions of mapper and core have bit stricter dependencies.
Specifically: version of core should not be much older than version of mapper, as newer mapper versions depend on new features in core. Reverse matters less; so it is generally fine to have older mapper version, newer core (core also changes at much slower pace at this point).
I found the problem.
Use Jacson version 1.4.2 should not have problem and as StaxMan suggested core is dependably for mapper so it will be automatically resolved no need to declare it explicitly.
Now coming back to problem. It is classpath issue within jboss. I have two web application deployed in same server one with dependency on jacson versioin 1.1.1 and other one with 1.4.2. I dont yet have solution, So I have posted another question related to Jboss.

Categories

Resources