无法写入JSON:找不到类net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding的序列化程序

问题描述 投票:1回答:3

我尝试将spring web服务器实现为cordapp,但不断获得相同的序列化错误。

{
"timestamp": 1529999846743,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.http.converter.HttpMessageNotWritableException",
"message": "org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0]->java.util.Collections$SingletonMap[\"state\"]->java.util.Collections$SingletonMap[\"data\"]->java.util.LinkedHashMap[\"exitKeys\"]->java.util.LinkedHashSet[0]->net.i2p.crypto.eddsa.EdDSAPublicKey[\"params\"]->net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec[\"curve\"]->net.i2p.crypto.eddsa.math.Curve[\"field\"]->net.i2p.crypto.eddsa.math.Field[\"encoding\"])",
"path": "/api/obligation/cash"

}

spring-boot corda
3个回答
2
投票

基本上你正在尝试序列化类net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding的对象,正如你在sources中看到的那样,这个类没有字段,导致序列化失败。

您应该将此行添加到映射器配置中:

mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

然后看看输出是否是你想要的。

编辑:根据Spring Boot documentation,您可以通过添加将此配置添加到默认映射器

spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false

到你的application.properties文件。


2
投票

在@Configuration类中创建一个ObjectMapper,如下所示:

@Configuration
class Plugin {

   @Bean
   fun registerModule(): ObjectMapper {
      return JacksonSupport.createNonRpcMapper()
   }
}

你很高兴去!


1
投票

当杰克逊试图将PublicKey类序列化为JSON format时,会抛出此错误。 Corda为一些内部类提供Jackson support,你必须在Spring中注册该模块:

  1. 在你的spring项目中添加corda-jackson依赖项。 net.corda:琴弦 - 杰克逊:3.1琴弦
  2. 注册Corda Jackson支持Module为您的春季项目。您可以使用java config执行此操作,如下所示:

@Bean public Module registerModule() { return JacksonSupport.INSTANCE.getCordaModule(); }

© www.soinside.com 2019 - 2024. All rights reserved.