jsonレスポンスのために安心してgrails rest-api用のsnippetを実装しようとしています:Grails 3.1.8:Spring Restドキュメントを使用して、残りのPayloadHandlingExceptionを確認しました。com.fasterxml.jackson.databind.JsonMappingException
void 'test and document get request for /user'() {
expect:
given(documentationSpec)
.header("AuthToken", "TokenValue")
.accept(MediaType.APPLICATION_JSON.toString())
.filter(document('user-list-v1',
preprocessRequest(modifyUris()
.host('127.0.0.1')
.removePort()),
preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath("[].firstName").description("First name of user"),
fieldWithPath("[].lastName").description("Last name of user"),
fieldWithPath("[].pictureUrl").type(JsonFieldType.STRING).description("Picture Url of user"),
fieldWithPath("[].email").description("Email address of user"),
fieldWithPath("[].bio").description("Bio data of user"),
fieldWithPath("totalCount").description("Count of instanceList field"),
fieldWithPath("type").description("Type of result")
))).
when()
.port(8080)
.get('/api/v1/user')
.then()
.assertThat()
.statusCode(is(200))
}
私にエラートレースを与えるこのコードの一部:
org.springframework.restdocs.payload.PayloadHandlingException: com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: [[email protected]; line: 1, column: 1]
at org.springframework.restdocs.payload.JsonContentHandler.readContent(JsonContentHandler.java:84)
at org.springframework.restdocs.payload.JsonContentHandler.findMissingFields(JsonContentHandler.java:50)
at org.springframework.restdocs.payload.AbstractFieldsSnippet.validateFieldDocumentation(AbstractFieldsSnippet.java:113)
at org.springframework.restdocs.payload.AbstractFieldsSnippet.createModel(AbstractFieldsSnippet.java:74)
at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:64)
at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:192)
at org.springframework.restdocs.restassured.RestDocumentationFilter.filter(RestDocumentationFilter.java:63)
at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73)
at com.jayway.restassured.filter.session.SessionFilter.filter(SessionFilter.java:60)
at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73)
at org.springframework.restdocs.restassured.RestAssuredRestDocumentationConfigurer.filter(RestAssuredRestDocumentationConfigurer.java:65)
at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73)
at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1574)
at com.jayway.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:159)
at com.converge.docs.UserApiDocumentationSpec.$tt__$spock_feature_0_0(UserApiDocumentationSpec.groovy:73)
at com.converge.docs.UserApiDocumentationSpec.test and document get request for /user_closure2(UserApiDocumentationSpec.groovy)
at groovy.lang.Closure.call(Closure.java:426)
at groovy.lang.Closure.call(Closure.java:442)
at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67)
at com.converge.docs.UserApiDocumentationSpec.test and document get request for /user(UserApiDocumentationSpec.groovy)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: [[email protected]; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3781)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3721)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2819)
at org.springframework.restdocs.payload.JsonContentHandler.readContent(JsonContentHandler.java:81)
... 21 more
{
"instanceList": [
{
"firstName": "Coy",
"lastName": "T",
"pictureUrl": null,
"email": "[email protected]",
"bio": null,
"skills": [],
"interestAreas": []
},
{
"firstName": "Jane",
"lastName": "D",
"pictureUrl": null,
"email": "[email protected]",
"bio": null,
"skills": [],
"interestAreas": []
},
{
"firstName": "Cause",
"lastName": "C",
"pictureUrl": "https://cc-picture.com",
"email": "[email protected]",
"bio": "cc beyond infinity",
"skills": [],
"interestAreas": []
},
{
"firstName": "sachidanand",
"lastName": "v",
"pictureUrl": null,
"email": "[email protected]",
"bio": null,
"skills": [],
"interestAreas": []
}
],
"totalCount": 4
}
と(IntegrationTestなど)UserDocumentationApiSpecのコードスニペット私は間違っているつもりだところ、私を修正してください
...
'http://127.0.0.1:8080/api/v1/user'へのgetリクエストからの応答が有効なJSONではないようです。あなたがそれを巻くなら、どんな反応を得ますか? –
**クライアントからの** http://127.0.0.1:8080/api/v1/user'のヒット**上記のように、** json **の応答が得られました.200 okステータス –
あなたの質問に表示されている回答有効ではありませんJSON –