我需要将一个对象转换为 Json 格式,为此我下载了 jackson-core-2.9.5.jar 文件并将其添加到 Bluej 中的库中,使用: 工具->首选项->库->添加文件,然后我重新启动了 Bluej。
然后在我的类文件中添加:
import com.fasterxml.jackson.core.JsonParser;
问题是当我尝试使用以下方法将对象序列化为 Json 时:
ObjectMapper objectMapper = new ObjectMapper();
Car car = new Car("yellow", "renault");
我得到:
cannot find symbol - class ObjectMapper
我使用了错误的导入吗?或者我还应该在 Bluej 做些什么?
最佳答案
您需要 ObjectMapper 的此依赖项
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>
关于java - 如何在 Java 和 Bluej 中使用 Jackson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50147807/