Java 无法与杰克逊合作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25947238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot work with Hymanson
提问by Misagh Emamverdi
I am wondering why there is not a determined way to work with Hymanson
. I just want to parse JSON
string:
我想知道为什么没有确定的方法来使用Hymanson
. 我只想解析JSON
字符串:
ObjectMapper mapper = new ObjectMapper();
Customer[] myObjects = mapper.readValue(file, Customer[].class);
But I really confused what should I import to do that. According to this link, I tried to import mapper-asl.jar
. But I get this compile error:
但我真的很困惑我应该导入什么来做到这一点。根据此链接,我尝试导入mapper-asl.jar
. 但我得到这个编译错误:
The type org.codehaus.Hymanson.JsonParser cannot be resolved. It is indirectly referenced from required .class files
Then I try to import Hymanson-core-2.4.2
and Hymanson-databind-2.4.2
. So there was no compile error but I got this runtime exception instead (in mapper definition line):
然后我尝试导入Hymanson-core-2.4.2
和Hymanson-databind-2.4.2
. 所以没有编译错误,但我得到了这个运行时异常(在映射器定义行中):
java.lang.NoClassDefFoundError: com.fasterxml.Hymanson.annotation.JsonAutoDetect
Guide me please what should I import to work with Hymanson
. Thanks
请指导我,我应该导入什么来使用Hymanson
. 谢谢
采纳答案by Kumar
use these dependencies
Hymanson-databind
Hymanson-annotations
Hymanson-core
使用这些依赖
Hymanson-databind
Hymanson-annotations
Hymanson-core
public class JsonTest {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper=new ObjectMapper();
Map<String,String> dt=new Hashtable();
dt.put("1", "welcome");
dt.put("2", "bye");
String jsonString = mapper.writeValueAsString(dt)
System.out.println(jsonString);
}
}
回答by Mena
Looks like mixed up references.
看起来像混合参考。
You might be using a library that uses an old version of Hymanson itself (i.e. the org.codehaus
package)...
您可能正在使用一个使用旧版本 Hymanson 本身(即org.codehaus
包)的库......
I usually just reference Hymanson through Maven.
我通常只是通过 Maven 引用 Hymanson。
Something like:
就像是:
<dependencies>
<dependency>
<groupId>com.fasterxml.Hymanson.core</groupId>
<artifactId>Hymanson-annotations</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.Hymanson.core</groupId>
<artifactId>Hymanson-core</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.Hymanson.core</groupId>
<artifactId>Hymanson-databind</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>