在测试时发现,当使用resttemplate去获取远端数据时,springboot框架无法自动将收到的json数据自动反序列化成指定的类对象。需要将对应的类的每个属性都加上@JsonProperty注解,并注明对应的Json字段名才可以,比如如下:
data class Bank(
@JsonProperty("account_number")
val accountNumber: String,
@JsonProperty("trust")
val trust: Double,
@JsonProperty("bank_transaction_fee")
val transactionFee: Int
)
感觉好像是一个bug.
在使用SpringBoot框架的RestTemplate获取远端JSON数据时遇到反序列化问题。需手动为每个属性添加@JsonProperty注解并指定JSON字段名才能正确转换。

364

被折叠的 条评论
为什么被折叠?



