问题
How to register newly introduced Corda RPC ObjectMapper in Spring Boot?
Even after having below code in
@Configuration
class Jackson failing to serializeParty
object to JSON string.
@Bean
public JsonComponentModule jsonComponentModule() {
return new JsonComponentModule();
}
@Bean
@Primary
public ObjectMapper cordaRpcObjectMapper(NodeRPCConnection rpc) {
ObjectMapper objectMapper = JacksonSupport.createDefaultMapper(rpc.getProxy(), new JsonFactory(), true);
objectMapper.registerModule(jsonComponentModule());
return objectMapper;
}
回答1:
After some tweaks I'm successfully able to register
Corda RPC ObjectMapper
with Jackson with below code.
//Register any other custom (de)Serializer classes.
@Bean
public Module jsonComponentModule() {
return new JsonComponentModule();
}
//Force Spring/Jackson to use only provided Corda ObjectMapper for serialization.
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(@Autowired NodeRPCConnection rpcConnection) {
ObjectMapper mapper = JacksonSupport.createDefaultMapper(rpcConnection.getProxy()/*, new JsonFactory(), true*/);
mapper.registerModule(jsonComponentModule());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(mapper);
return converter;
}
来源:https://stackoverflow.com/questions/51895899/corda-rpc-jacksonsupport-createdefaultmapper-to-use-objectmapper-in-spring-clien