Could not write JSON: No serializer found for class net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding

旧时模样 提交于 2019-12-11 06:48:19

问题


i try to implement spring web server to a cordapp , but continuously getting same Serialization error.

{
"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"

}


回答1:


Basically you're trying to serialize an object of class net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding and as you can see in the sources this class has no fields, which causes the serialization to fail.

You should add this line to your mapper configuration:

mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

then see if the output is what you want.

Edit: According to Spring Boot documentation, you can add this configuration to the default mapper by adding

spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false

to your application.properties file.




回答2:


create an ObjectMapper in a @Configuration class like this :

@Configuration
class Plugin {

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

and you are good to go !




回答3:


This error throws when Jackson tries to serialize the PublicKey class to JSON format. Corda provides Jackson support for some intrinsic classes and you have to register that module in Spring:

  1. Add corda-jackson dependency in your spring project.

    net.corda:corda-jackson:3.1-corda

  2. Register the Corda Jackson Support Module for your spring project. You can do it using java config as below:

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




回答4:


Please use this at class level for the bean:

@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler"})


来源:https://stackoverflow.com/questions/51037963/could-not-write-json-no-serializer-found-for-class-net-i2p-crypto-eddsa-math-ed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!