ObjectMapper cannot be allowed for type

I have problems working with JSON. ObjectMapper cannot be resolved. The library is imported correctly.

 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.jackson.*; 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(); } } } 
+5
source share
1 answer

If you are using a maven project, add the following to POM.xml

 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.1.2</version> </dependency> 

But if you are using a simple java project, you need to add the following jars to your class path:

 jackson-core-2.1.X, jackson-databind-2.1.X 
+3
source

Source: https://habr.com/ru/post/1238273/


All Articles