Jackson dataformat csv NoSuchMethodError createContentReference

huangapple go评论85阅读模式
英文:

Jackson dataformat csv NoSuchMethodError createContentReference

问题

I'm using jackson-dataformat-csv 2.15.0 with following code to export my data into an text file

List<HashMap<String, String>> data = <list of data>;
PrintWriter out = new PrintWriter(new File(FILE_PATH));
CsvSchema schema = null;
CsvSchema.Builder schemaBuilder = CsvSchema.builder();
// output verify list record
if (data != null && !data.isEmpty()) {
    schema = schemaBuilder.addColumn("ID").addColumn("Date").build()
            .withLineSeparator("\r").withHeader();

    CsvMapper mapper = new CsvMapper();
    mapper.writer(schema).writeValues(out).writeAll(data);
}
out.close();

But it just pop up error

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) Exception in thread "Thread-394" java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.csv.CsvFactory._createContentReference(Ljava/lang/Object;)Lcom/fasterxml/jackson/core/io/ContentReference;

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.dataformat.csv.CsvFactory.createGenerator(CsvFactory.java:372)

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.dataformat.csv.CsvFactory.createGenerator(CsvFactory.java:16)

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.databind.ObjectWriter.createGenerator(ObjectWriter.java:703)

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.databind.ObjectWriter.writeValues(ObjectWriter.java:789)

I have checked maven hierarchy, those conflicted jackson libs are ommited. I also checked the exported WAR that its jackson-core, jackson-annotations, jackson-databind, and jackson-dataformat-csv are 2.15.0 and no other old-duplicated lib. No error reported from my eclipse about method not found or otherwise. Does anyone know what happen about this?

英文:

I'm using jackson-dataformat-csv 2.15.0 with following code to export my data into an text file

            List&lt;HashMap&lt;String, String&gt;&gt; data = &lt;list of data&gt;;
            PrintWriter out = new PrintWriter(new File(FILE_PATH));
            CsvSchema schema = null;
			CsvSchema.Builder schemaBuilder = CsvSchema.builder();
			// output verify list record
			if (data != null &amp;&amp; !data.isEmpty()) {
				schema = schemaBuilder.addColumn(&quot;ID&quot;).addColumn(&quot;Date&quot;).build()
						.withLineSeparator(&quot;\r&quot;).withHeader();

				CsvMapper mapper = new CsvMapper();
				mapper.writer(schema).writeValues(out).writeAll(data);
			}
            out.close();

But it just pop up error

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) Exception in thread &quot;Thread-394&quot; java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.csv.CsvFactory._createContentReference(Ljava/lang/Object;)Lcom/fasterxml/jackson/core/io/ContentReference;

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.dataformat.csv.CsvFactory.createGenerator(CsvFactory.java:372)

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.dataformat.csv.CsvFactory.createGenerator(CsvFactory.java:16)

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.databind.ObjectWriter.createGenerator(ObjectWriter.java:703)

2023-05-14 14:11:25,865 ERROR [stderr] (Thread-394) 	at com.fasterxml.jackson.databind.ObjectWriter.writeValues(ObjectWriter.java:789)

I have checked maven hierarchy, those conflicted jackson libs are ommited. I also checked the exported WAR that its jackson-core, jackson-annotations, jackson-databind, and jackson-dataformat-csv are 2.15.0 and no other old-duplicated lib. No error reported from my eclipse about method not found or otherwise. Does anyone know what happen about this?

答案1

得分: 0

Here is the translated content:

"通过进一步的调查和从jackson库的成员那里得到的一些提示,事实证明这不是我的WAR的问题,而是JBoss的问题。他们的默认设置会使用一个名为resteasy-jackson2-provider的模块,即使您的服务器配置不包括它们,它也会使用jackson-corejackson-databind作为其依赖项的一部分。这是一种间接依赖关系。

解决此问题有两种方法,我更喜欢第一种,因为麻烦较少。

  1. 在您的jboss-deployment-structure.xml中排除它们

    正如我提到的,这是一种间接依赖关系。因此,您必须排除的库是resteasy-jackson2-provider。如果您不确定其他JBoss是否会包含它们,可以将它们全部添加到排除列表中。

    <exclusions>
        <module name="com.fasterxml.jackson.core.jackson-core" />
        <module name="com.fasterxml.jackson.core.jackson-databind" />
        <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
    </exclusions>
    
  2. 更新JBoss的模块

    如果您有很多模块,这将非常烦人。"

英文:

With further digging and some tips from the jackson lib's member, it turn out that isn't my WAR's fault but JBoss. Their default setting would use a module call resteasy-jackson2-provider and it will be using jackson-core and jackson-databind as part of its dependencies even if your server config doesn't includes them. It's indirect dependency.

There are two ways to resolve this issue, I prefer first one for less trouble.

  1. Exclude them in your jboss-deployment-structure.xml

    As I mentioned that this is indirect dependency. So the lib that you have to exclude would be resteasy-jackson2-provider. Add them all to exclusions if you're not sure that the other JBoss would include them or not.

    &lt;exclusions&gt;
    	&lt;module name=&quot;com.fasterxml.jackson.core.jackson-core&quot; /&gt;
    	&lt;module name=&quot;com.fasterxml.jackson.core.jackson-databind&quot; /&gt;
    	&lt;module name=&quot;org.jboss.resteasy.resteasy-jackson2-provider&quot; /&gt;
    &lt;/exclusions&gt;
    
  2. Update JBoss's modules

    Well, this WILL be super annoying if you have many of them.

huangapple
  • 本文由 发表于 2023年5月15日 14:38:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定