问题
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:
- Add
corda-jacksondependency in your spring project.net.corda:corda-jackson:3.1-corda
- Register the Corda Jackson Support
Modulefor 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