Merge pull request #680 from Inujel/fix-673

Fix parsing of Boolean
This commit is contained in:
Leonid Stryzhevskyi 2022-12-10 03:15:02 +02:00 committed by GitHub
commit e4902ea410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 137 additions and 1 deletions

View File

@ -126,7 +126,7 @@ public:
auto type = Wrapper::Class::getType();
oatpp::parser::Caret caret(str);
auto result = read(caret, type).template cast<Wrapper>();
if(!result) {
if(result == nullptr) {
throw oatpp::parser::ParsingError(caret.getErrorMessage(), caret.getErrorCode(), caret.getPosition());
}
return result;

View File

@ -75,6 +75,8 @@ add_executable(oatppAllTests
oatpp/parser/json/mapping/DeserializerTest.hpp
oatpp/parser/json/mapping/EnumTest.cpp
oatpp/parser/json/mapping/EnumTest.hpp
oatpp/parser/json/mapping/BooleanTest.cpp
oatpp/parser/json/mapping/BooleanTest.hpp
oatpp/parser/json/mapping/UnorderedSetTest.cpp
oatpp/parser/json/mapping/UnorderedSetTest.hpp
oatpp/web/protocol/http/encoding/ChunkedTest.cpp

View File

@ -22,6 +22,7 @@
#include "oatpp/parser/json/mapping/DTOMapperPerfTest.hpp"
#include "oatpp/parser/json/mapping/DTOMapperTest.hpp"
#include "oatpp/parser/json/mapping/EnumTest.hpp"
#include "oatpp/parser/json/mapping/BooleanTest.hpp"
#include "oatpp/parser/json/mapping/UnorderedSetTest.hpp"
#include "oatpp/encoding/UnicodeTest.hpp"
@ -122,6 +123,7 @@ void runTests() {
OATPP_RUN_TEST(oatpp::test::core::provider::PoolTemplateTest);
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::EnumTest);
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::BooleanTest);
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::UnorderedSetTest);

View File

@ -0,0 +1,78 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "BooleanTest.hpp"
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace oatpp
{
namespace test
{
namespace parser
{
namespace json
{
namespace mapping
{
void BooleanTest::onRun()
{
oatpp::parser::json::mapping::ObjectMapper mapper;
{
OATPP_LOGI(TAG, "Serialize true to string...");
auto value = mapper.writeToString(Boolean(true));
OATPP_ASSERT(value == "true");
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "Serialize false to string...");
auto value = mapper.writeToString(Boolean(false));
OATPP_ASSERT(value == "false");
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "Deserialize true string...");
Boolean value = mapper.readFromString<Boolean>("true");
OATPP_ASSERT(static_cast<bool>(value));
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "Deserialize false string...");
Boolean value = mapper.readFromString<Boolean>("false");
OATPP_ASSERT(!static_cast<bool>(value));
OATPP_LOGI(TAG, "OK");
}
}
} // namespace mapping
} // namespace json
} // namespace parser
} // namespace test
} // namespace oatpp

View File

@ -0,0 +1,54 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_test_parser_json_mapping_BooleanTest_hpp
#define oatpp_test_parser_json_mapping_BooleanTest_hpp
#include "oatpp-test/UnitTest.hpp"
namespace oatpp
{
namespace test
{
namespace parser
{
namespace json
{
namespace mapping
{
class BooleanTest : public UnitTest
{
public:
BooleanTest() : UnitTest("TEST[parser::json::mapping::BooleanTest]") {}
void onRun() override;
};
} // namespace mapping
} // namespace json
} // namespace parser
} // namespace test
} // namespace oatpp
#endif /* oatpp_test_parser_json_mapping_BooleanTest_hpp */