java–Spring:缺少必需的请求体.无法将JSON传递给RestController

java–Spring:缺少必需的请求体.无法将JSON传递给RestController,第1张

概述我有将JSON传递给RestController的问题.它似乎没有消耗它.控制器:@PostMapping(path = 'Users/{UserId}/Transactions', consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLIC

我有将JSON传递给RestController的问题.它似乎没有消耗它.

控制器:

@PostMapPing(path = "Users/{UserID}/Transactions",consumes = MediaType.APPliCATION_JsON_VALUE,produces = MediaType.APPliCATION_JsON_VALUE)public CompletableFuture

TransactionRequest对象模型:

public class TransactionRequest {@JsonProperty("TransactionType")private TransactionType transactionType;@JsonProperty("TransactionID")private String transactionID;@JsonProperty("TransactionCreationDate")private LocalDateTime transactionCreationDate;@JsonProperty("Amount")private Long amount;@JsonProperty("Rake")private BigDecimal rake;@JsonProperty("CurrencyCode")private String currencyCode;@JsonProperty("EntityReferences")private List

这是试图发布到控制器的测试方法:

def createTransactionRequest(Integer roundNum,String transType,BigDecimal transactionAmount) {    def transactionRequest = builder{        'TransactionType' transType        'TransactionID' "${new Random().nextInt(50)}"        'TransactionCreationDate' LocalDateTime.Now().toString()        'Amount' transactionAmount.longValue()        'Rake' 0.0        'CurrencyCode' userCurrencyCode        'EntityReferences' builder.call([                { 'EntityType' "Casinoround"; 'EntityID' roundNum },{ 'EntityType' "CasinoSession"; 'EntityID' gameSessionID }        ])        'Game' (GameID: "111",Gamename: "Some Game")    }    String currentDate = zoneddatetime.Now(ZoneID.of("UTC")).format(DATE_FORMATTER)    def authorizationheader = buildAuthheader("POST","Users/${player.uuID}/Transactions?PartnerUserSessionKey=$gameSessionID",JsonOutput.toJson(transactionRequest),currentDate)    return clIEnt.post(path: "Users/${player.uuID}/Transactions",query: ["PartnerUserSessionKey": gameSessionID],headers: ['Authorization' : authorizationheader,DateUtc : currentDate]) {        type "application/Json"        Json transactionRequest    }}

测试方法是用Groovy编写的.和groovy.Json.JsonBuilder中的Builder一样. (忽略authorizationheader方法,它只是为了生成授权签名,它工作)我尝试过只发送几个参数,但每次都会给我相同的错误.这是错误:

2017-09-05 12:38:26,005 WARN  c.n.c.e.CommonExceptionHandler - required request body is missing: public java.util.concurrent.CompletableFuture

我相信它有对象模型的东西,但不知道是什么.我试过传递不同的组合,但没有运气.它只会给我所需的请求正文丢失.

这是生成的JsON:

{"TransactionType":"Casinoround_Stake","TransactionID":"31","TransactionCreationDate":"2017-09-05T15:38:08.610","Amount":400,"Rake":0.0,"CurrencyCode":"EUR","EntityReferences":[{"EntityType":"Casinoround","EntityID":1},{"EntityType":"CasinoSession","EntityID":"9f31d8b9-28f7-4931-bb9d-73f90c2b2de7"}],"Game":{"GameID":"111","Gamename":"Some Game"}}
最佳答案你可能有一个过滤器,你已经读过它了. 总结

以上是内存溢出为你收集整理的java – Spring:缺少必需的请求体.无法将JSON传递给RestController全部内容,希望文章能够帮你解决java – Spring:缺少必需的请求体.无法将JSON传递给RestController所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1258199.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)