英文:
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<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?
答案1
得分: 0
Here is the translated content:
"通过进一步的调查和从jackson库的成员那里得到的一些提示,事实证明这不是我的WAR的问题,而是JBoss的问题。他们的默认设置会使用一个名为resteasy-jackson2-provider
的模块,即使您的服务器配置不包括它们,它也会使用jackson-core
和jackson-databind
作为其依赖项的一部分。这是一种间接依赖关系。
解决此问题有两种方法,我更喜欢第一种,因为麻烦较少。
-
在您的
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>
-
更新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.
-
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.<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>
-
Update JBoss's modules
Well, this WILL be super annoying if you have many of them.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论