diff --git a/src/oatpp/core/data/mapping/ObjectMapper.hpp b/src/oatpp/core/data/mapping/ObjectMapper.hpp index 40ac07fd..e4c2a42f 100644 --- a/src/oatpp/core/data/mapping/ObjectMapper.hpp +++ b/src/oatpp/core/data/mapping/ObjectMapper.hpp @@ -126,7 +126,7 @@ public: auto type = Wrapper::Class::getType(); oatpp::parser::Caret caret(str); auto result = read(caret, type).template cast(); - if(result == nullptr) { + if(caret.hasError()) { throw oatpp::parser::ParsingError(caret.getErrorMessage(), caret.getErrorCode(), caret.getPosition()); } return result; diff --git a/test/oatpp/web/FullTest.cpp b/test/oatpp/web/FullTest.cpp index df3e6129..e528e152 100644 --- a/test/oatpp/web/FullTest.cpp +++ b/test/oatpp/web/FullTest.cpp @@ -341,6 +341,46 @@ void FullTest::onRun() { OATPP_ASSERT(returnedData == data) } + { + String bodyIn = "null"; + auto response = client->testBodyIsNull1(bodyIn, connection); + OATPP_ASSERT(response->getStatusCode() == 400) + auto returnedData = response->readBodyToString(); + OATPP_ASSERT(returnedData) + OATPP_ASSERT(returnedData == "server=oatpp/" OATPP_VERSION "\n" + "code=400\n" + "description=Bad Request\n" + "message=Missing valid body parameter 'body'\n") + connection = client->getConnection(); + } + + { + String bodyIn = "\"null\""; + auto response = client->testBodyIsNull1(bodyIn, connection); + OATPP_ASSERT(response->getStatusCode() == 200) + auto returnedData = response->readBodyToString(); + OATPP_ASSERT(returnedData) + OATPP_ASSERT(returnedData == "OK---null") + } + + { + String bodyIn = "null"; + auto response = client->testBodyIsNull2(bodyIn, connection); + OATPP_ASSERT(response->getStatusCode() == 200) + auto returnedData = response->readBodyToString(); + OATPP_ASSERT(returnedData) + OATPP_ASSERT(returnedData == "OK---null") + } + + { + String bodyIn = "\"null\""; + auto response = client->testBodyIsNull2(bodyIn, connection); + OATPP_ASSERT(response->getStatusCode() == 200) + auto returnedData = response->readBodyToString(); + OATPP_ASSERT(returnedData) + OATPP_ASSERT(returnedData == "OK---\"null\"") + } + { auto response = client->headerValueSet(" VALUE_1, VALUE_2, VALUE_3", connection); OATPP_ASSERT(response->getStatusCode() == 200) diff --git a/test/oatpp/web/app/Client.hpp b/test/oatpp/web/app/Client.hpp index a6ab7224..db591dc5 100644 --- a/test/oatpp/web/app/Client.hpp +++ b/test/oatpp/web/app/Client.hpp @@ -62,6 +62,8 @@ public: API_CALL("GET", "enum/as-number", getHeaderEnumAsNumber, HEADER(Enum::AsNumber, enumValue, "enum")) API_CALL("POST", "echo", echoBody, BODY_STRING(String, body)) + API_CALL("POST", "testBodyIsNull1", testBodyIsNull1, BODY_STRING(String, body)) + API_CALL("POST", "testBodyIsNull2", testBodyIsNull2, BODY_STRING(String, body)) API_CALL("GET", "header-value-set", headerValueSet, HEADER(String, valueSet, "X-VALUE-SET")) API_CALL("GET", "default-basic-authorization", defaultBasicAuthorization, AUTHORIZATION_BASIC(String, authString)) diff --git a/test/oatpp/web/app/Controller.hpp b/test/oatpp/web/app/Controller.hpp index 16669997..460dc91c 100644 --- a/test/oatpp/web/app/Controller.hpp +++ b/test/oatpp/web/app/Controller.hpp @@ -62,7 +62,7 @@ public: , available(true) {} public: - + static std::shared_ptr createShared(const std::shared_ptr& objectMapper = OATPP_GET_COMPONENT(std::shared_ptr)){ return std::make_shared(objectMapper); } @@ -110,7 +110,7 @@ public: dto->testValue = param; return createDtoResponse(Status::CODE_200, dto); } - + ENDPOINT("GET", "queries", getWithQueries, QUERY(String, name), QUERY(Int32, age)) { auto dto = TestDto::createShared(); @@ -134,7 +134,7 @@ public: } return createDtoResponse(Status::CODE_200, dto); } - + ENDPOINT("GET", "headers", getWithHeaders, HEADER(String, param, "X-TEST-HEADER")) { //OATPP_LOGV(TAG, "GET headers {X-TEST-HEADER: %s}", param->c_str()) @@ -142,7 +142,7 @@ public: dto->testValue = param; return createDtoResponse(Status::CODE_200, dto); } - + ENDPOINT("POST", "body", postBody, BODY_STRING(String, body)) { //OATPP_LOGV(TAG, "POST body %s", body->c_str()) @@ -163,6 +163,16 @@ public: return createResponse(Status::CODE_200, body); } + ENDPOINT("POST", "testBodyIsNull1", testBodyIsNull1, + BODY_DTO(String, body)) { + return createResponse(Status::CODE_200, "OK---" + body); + } + + ENDPOINT("POST", "testBodyIsNull2", testBodyIsNull2, + BODY_STRING(String, body)) { + return createResponse(Status::CODE_200, "OK---" + body); + } + ENDPOINT("GET", "header-value-set", headerValueSet, HEADER(String, valueSet, "X-VALUE-SET")) {