java - 无法解析我在春季云流中使用活页夹收到的 Json 对象
问题描述
我的 Json 转换器有问题,当我尝试收听该对象并将其转换为 java 对象时,我正在使用 spring 云流在 rabbitmq 中发送一个 Json 对象。
这是我收到对象的地方:
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.Ebanking.transactionservice.entities.Transaction;
import org.Ebanking.transactionservice.repositories.TransactionRepository;
import org.Ebanking.transactionservice.services.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
@EnableBinding(Sink.class)
public class TransactionServiceImpl implements TransactionService {
@Autowired
TransactionRepository transactionRepository;
@Override
@StreamListener(target = Sink.INPUT)
public void listen(String payload) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Transaction transaction = mapper.readValue(payload,Transaction.class);
transactionRepository.save(transaction);
System.out.println("Transaction registered Successfully");
}
}
这是我发送对象的地方:
@StreamListener(target = Processor.INPUT)
@SendTo(Processor.OUTPUT)
public String processTransaction(Transaction transaction) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Long idDebi = transaction.getAccountId();
Long idCred = transaction.getAccountIdDestination();
Double amount = transaction.getAmount();
String str = mapper.writeValueAsString(transaction);
if (debitAccount(idDebi, amount).equals(true) && creditAccount(idCred, amount).equals(true)) {
processor.output().send(MessageBuilder.withPayload(str).setHeader("treatedTran","treatment").build());
return "transaction treated successfully";
}
else return "transaction failed";
} ```
解决方案
?
您不是在发送Transaction
对象;你只是发送字符串
public String processTransaction(
...
return "transaction treated successfully";
}
else return "transaction failed";
推荐阅读
- python - Tensorflow 镜像策略错误:Non-OK-status: GpuLaunchKernel(SwapDimension1And2InTensor3UsingTiles)
- svg - Snap.svg 未能 .transform() for
- python - 如何在忽略背景噪声/模糊来训练神经网络的同时隔离图像中的矩形?
- reactjs - 为什么 opacity 过渡不起作用,并且 Jobs 组件突然出现没有 opacity 过渡?
- python - 如何应用滚动平均函数,同时及时保持所有具有重复索引的观测值
- python - 不支持的链接:Spotify、Discord.py 音乐机器人
- mongodb - 如何从 MongoDB 中的数组中获取多个元素?
- gnome - 在 Gnome Builder 中调试时如何更改变量值?
- amazon-web-services - 我可以在本地目录中创建(或模拟)AWS 凭证文件吗?
- windows - 如何获得我在 Windows 10 中选择的文件夹的预览图像?