我正在使用Maven-EJB并希望将java对象转换为JSON,我使用Jackson jars lib但是我得到了:
java.lang.ClassNotFoundException:com.fasterxml.jackson.core.Versioned
我在pom.xml文件中添加了这些依赖项:
在Java Facade中的<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-jaxb-annotations</artifactId> <version>2.4.0</version> </dependency> </dependencies>
我写这行来转换:
String json =&#34;&#34 ;;
try { ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); json = ow.writeValueAsString(userlist); } catch (JsonProcessingException e) { throw new BusinessException("error_json"); }
这是进口商品:
import com.fasterxml.jackson.core.JsonProcessingException;进口 com.fasterxml.jackson.databind.ObjectMapper;进口 com.fasterxml.jackson.databind.ObjectWriter;
我检查了类路径并进行了大量清理并构建但没有办法,,,出现同样的异常!!
我正在研究NetBeans8和Java 1.7
提前致谢 玛丽亚姆
答案 0 :(得分:-1)
感谢Couettos,它有效,我检查了应用服务器和maven jar的版本然后我下载了最新的2.4.0 jackson jar并升级了带有2.4.0版本的glassfish lib jar