Java ObjectMapper 无法解析为类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34290913/
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
ObjectMapper cannot be resolved to a type
提问by Jürgen K.
I have troubles getting JSON to work. ObjectMapper
cannot be resolved. Library is imported correctly.
我在使用 JSON 时遇到了麻烦。ObjectMapper
无法解决。库已正确导入。
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONException;
import net.sf.json.util.*;
import com.fasterxml.Hymanson.*;
public class Json {
private static final String jsonFilePath = "C:\Users\Juergen\Desktop\filesForExamples\mapExample.json";
public static void objectToJSON(HashMap<String, Mat> map) {
//Map<String, Object> mapObject = new HashMap<String, Object>();
ObjectMapper mapper = new ObjectMapper();
try {
objectMapper.writeValue(new File(jsonFilePath), map);
} catch (IOException e) {
e.printStackTrace();
}
}
}
回答by Rohit Yadav
If you are using mavenproject then add the following in the POM.xml
如果您使用的是maven项目,则在POM.xml
<dependency>
<groupId>com.fasterxml.Hymanson.core</groupId>
<artifactId>Hymanson-databind</artifactId>
<version>2.1.2</version>
</dependency>
But if you are using a simple javaproject then you need to add the following jars in your class path:
但是如果你使用的是一个简单的 java项目,那么你需要在你的类路径中添加以下 jars:
Hymanson-core-2.1.X,
Hymanson-databind-2.1.X
回答by Vishwa Ratna
Add import com.fasterxml.Hymanson.databind.ObjectMapper;
to your project.
添加import com.fasterxml.Hymanson.databind.ObjectMapper;
到您的项目中。