java - JsonMappingException 的 Spring Boot 测试给出了低于标准的堆栈跟踪

标签 java spring-boot jackson

Spring 集成测试,定义为

@RunWith(SpringRunner.class)
@SpringBootTest(classes = HiVssFormioWrapperApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@TestPropertySource(locations= {"classpath:application.properties", "classpath:application-integration-test.properties"})

最近开始失败,但是堆栈跟踪几乎没有提供有关在哪里查找的线索。它确实指出了问题所在,但没有指出问题所在。这是完整的堆栈跟踪,请注意实际上没有一个堆栈跟踪元素指向我们的代码:

org.opentest4j.MultipleFailuresError: Multiple Failures (2 failures)
    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of io.vavr.collection.List out of START_OBJECT token
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.gera.gsm.hivssformiowrapper.domain.periodpackage.DataPackage["department"]->com.gera.gsm.hivssformiowrapper.domain.Submission["data"]->com.gera.gsm.hivssformiowrapper.domain.Department["fillableForms"])
    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of io.vavr.collection.List out of START_OBJECT token
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.gera.gsm.hivssformiowrapper.domain.periodpackage.DataPackage["department"]->com.gera.gsm.hivssformiowrapper.domain.Submission["data"]->com.gera.gsm.hivssformiowrapper.domain.Department["fillableForms"])
    at org.junit.vintage.engine.execution.TestRun.getStoredResultOrSuccessful(TestRun.java:179)
    at org.junit.vintage.engine.execution.RunListenerAdapter.fireExecutionFinished(RunListenerAdapter.java:211)
    at org.junit.vintage.engine.execution.RunListenerAdapter.testFinished(RunListenerAdapter.java:177)
    at org.junit.vintage.engine.execution.RunListenerAdapter.testFinished(RunListenerAdapter.java:76)
    at org.junit.runner.notification.SynchronizedRunListener.testFinished(SynchronizedRunListener.java:56)
    at org.junit.runner.notification.RunNotifier$7.notifyListener(RunNotifier.java:190)
    at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
    at org.junit.runner.notification.RunNotifier.fireTestFinished(RunNotifier.java:187)
    at org.junit.internal.runners.model.EachTestNotifier.fireTestFinished(EachTestNotifier.java:38)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:331)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:40)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
    at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
    at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
    at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:71)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

我对 MultipleFailuresError 表示怀疑,因为它可能会吞噬正确的堆栈跟踪,但谷歌搜索“disable junit MultipleFailuresError”并没有带来任何有用的东西。

这可能不是 Eclipse 的问题,因为从命令行使用 Maven 运行会给出类似的结果。

使用的版本是

  • Java:OpenJDK13
  • SpringBoot:2.2.0.RELEASE

    查看依赖关系层次结构,这会带来

    • junit 4.12
    • jackson 2.10
  • Vavr:0.10

最佳答案

异常(exception)情况是 JSON Serializer Jackson 无法序列化 Vavr List 类。

您必须添加 Vavr Jacksion 支持才能使其正常工作。

<dependency>
    <groupId>io.vavr</groupId>
    <artifactId>vavr-jackson</artifactId>
    <version>0.10.2</version>
</dependency>

关于java - JsonMappingException 的 Spring Boot 测试给出了低于标准的堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60845061/

相关文章:

java - 使用Jboss部署简单的War文件(J2EE应用程序)时出错

java - 在聊天服务器程序中从单个类运行多个客户端

java - 找不到类 java.util.logging.ErrorManager 的序列化程序,也没有发现用于创建 BeanSerializer 的属性

java - 在 for 循环中使用 Hibernate save 方法将对象持久保存在数据库中的方法

java - 使用 Jackson 序列化自定义 map

java - com.google.auth.oauth2.GoogleCredentials.createScoped 处出现 StackOverflowError(GoogleCredentials.java :222)

java - 此代码中 AES key 所需的大小是多少?

java - 无法传递以# 开头的参数?

java - 如何获取 Jackson JsonNode 的路径

java - 使用 Swagger 注释时响应中缺少 JSON 父/根元素