mirror of
https://github.com/oatpp/oatpp.git
synced 2024-11-27 08:30:07 +08:00
parser::json. Add ser/de for oatpp::UnorderedSet.
This commit is contained in:
parent
70e898f86d
commit
5f213dd853
@ -118,12 +118,6 @@ namespace oatpp {
|
||||
template <class T>
|
||||
using Vector = oatpp::data::mapping::type::Vector<T>;
|
||||
|
||||
/*
|
||||
* Mapping-Enabled UnorderedSet. &id:oatpp::data::mapping::type::UnorderedSet;
|
||||
*/
|
||||
template <class T>
|
||||
using UnorderedSet = oatpp::data::mapping::type::UnorderedSet<T>;
|
||||
|
||||
/**
|
||||
* Abstract Vector.
|
||||
*/
|
||||
@ -140,6 +134,17 @@ namespace oatpp {
|
||||
*/
|
||||
typedef oatpp::data::mapping::type::AbstractList AbstractList;
|
||||
|
||||
/*
|
||||
* Mapping-Enabled UnorderedSet. &id:oatpp::data::mapping::type::UnorderedSet;
|
||||
*/
|
||||
template <class T>
|
||||
using UnorderedSet = oatpp::data::mapping::type::UnorderedSet<T>;
|
||||
|
||||
/**
|
||||
* Abstract UnorderedSet.
|
||||
*/
|
||||
typedef oatpp::data::mapping::type::AbstractUnorderedSet AbstractUnorderedSet;
|
||||
|
||||
/*
|
||||
* Mapping-Enables PairList<String, Value>. &id:oatpp::data::mapping::type::PairList;
|
||||
*/
|
||||
|
@ -82,8 +82,7 @@ public:
|
||||
* @param stream - &id:oatpp::data::stream::ConsistentOutputStream; to serialize object to.
|
||||
* @param variant - Object to serialize.
|
||||
*/
|
||||
virtual void write(data::stream::ConsistentOutputStream* stream,
|
||||
const type::Void& variant) const = 0;
|
||||
virtual void write(data::stream::ConsistentOutputStream* stream, const type::Void& variant) const = 0;
|
||||
|
||||
/**
|
||||
* Deserialize object. Implement this method.
|
||||
@ -91,8 +90,7 @@ public:
|
||||
* @param type - pointer to object type. See &id:oatpp::data::mapping::type::Type;.
|
||||
* @return - deserialized object wrapped in &id:oatpp::Void;.
|
||||
*/
|
||||
virtual mapping::type::Void read(oatpp::parser::Caret& caret,
|
||||
const mapping::type::Type* const type) const = 0;
|
||||
virtual mapping::type::Void read(oatpp::parser::Caret& caret, const mapping::type::Type* const type) const = 0;
|
||||
|
||||
/**
|
||||
* Serialize object to String.
|
||||
|
@ -416,5 +416,21 @@ public: \
|
||||
|
||||
|
||||
}}}}
|
||||
|
||||
namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<oatpp::data::mapping::type::Void> {
|
||||
|
||||
typedef oatpp::data::mapping::type::Void argument_type;
|
||||
typedef v_buff_usize result_type;
|
||||
|
||||
result_type operator()(argument_type const& v) const noexcept {
|
||||
return (result_type) v.get();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* oatpp_data_type_Type_hpp */
|
||||
|
@ -58,6 +58,7 @@ Deserializer::Deserializer(const std::shared_ptr<Config>& config)
|
||||
|
||||
setDeserializerMethod(data::mapping::type::__class::AbstractVector::CLASS_ID, &Deserializer::deserializeList<oatpp::AbstractVector>);
|
||||
setDeserializerMethod(data::mapping::type::__class::AbstractList::CLASS_ID, &Deserializer::deserializeList<oatpp::AbstractList>);
|
||||
setDeserializerMethod(data::mapping::type::__class::AbstractUnorderedSet::CLASS_ID, &Deserializer::deserializeList<oatpp::AbstractUnorderedSet>);
|
||||
|
||||
setDeserializerMethod(data::mapping::type::__class::AbstractPairList::CLASS_ID, &Deserializer::deserializeKeyValue<oatpp::AbstractFields>);
|
||||
setDeserializerMethod(data::mapping::type::__class::AbstractUnorderedMap::CLASS_ID, &Deserializer::deserializeKeyValue<oatpp::AbstractUnorderedFields>);
|
||||
|
@ -89,8 +89,7 @@ public:
|
||||
* @param stream - stream to write serializerd data to &id:oatpp::data::stream::ConsistentOutputStream;.
|
||||
* @param variant - object to serialize &id:oatpp::Void;.
|
||||
*/
|
||||
void write(data::stream::ConsistentOutputStream* stream,
|
||||
const oatpp::Void& variant) const override;
|
||||
void write(data::stream::ConsistentOutputStream* stream, const oatpp::Void& variant) const override;
|
||||
|
||||
/**
|
||||
* Implementation of &id:oatpp::data::mapping::ObjectMapper::read;.
|
||||
@ -98,8 +97,7 @@ public:
|
||||
* @param type - type of resultant object &id:oatpp::data::mapping::type::Type;.
|
||||
* @return - &id:oatpp::Void; holding resultant object.
|
||||
*/
|
||||
oatpp::Void read(oatpp::parser::Caret& caret,
|
||||
const oatpp::data::mapping::type::Type* const type) const override;
|
||||
oatpp::Void read(oatpp::parser::Caret& caret, const oatpp::data::mapping::type::Type* const type) const override;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -59,6 +59,7 @@ Serializer::Serializer(const std::shared_ptr<Config>& config)
|
||||
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractVector::CLASS_ID, &Serializer::serializeList<oatpp::AbstractVector>);
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractList::CLASS_ID, &Serializer::serializeList<oatpp::AbstractList>);
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractUnorderedSet::CLASS_ID, &Serializer::serializeList<oatpp::AbstractUnorderedSet>);
|
||||
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractPairList::CLASS_ID, &Serializer::serializeKeyValue<oatpp::AbstractFields>);
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractUnorderedMap::CLASS_ID, &Serializer::serializeKeyValue<oatpp::AbstractUnorderedFields>);
|
||||
|
@ -65,6 +65,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/UnorderedSetTest.cpp
|
||||
oatpp/parser/json/mapping/UnorderedSetTest.hpp
|
||||
oatpp/web/protocol/http/encoding/ChunkedTest.cpp
|
||||
oatpp/web/protocol/http/encoding/ChunkedTest.hpp
|
||||
oatpp/web/mime/multipart/StatefulParserTest.cpp
|
||||
|
@ -31,6 +31,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/UnorderedSetTest.hpp"
|
||||
|
||||
#include "oatpp/encoding/UnicodeTest.hpp"
|
||||
#include "oatpp/encoding/Base64Test.hpp"
|
||||
@ -58,7 +59,6 @@
|
||||
|
||||
#include "oatpp/core/async/Coroutine.hpp"
|
||||
#include "oatpp/core/Types.hpp"
|
||||
#include "oatpp/core/data/mapping/type/Enum.hpp"
|
||||
|
||||
#include "oatpp/core/concurrency/SpinLock.hpp"
|
||||
#include "oatpp/core/base/Environment.hpp"
|
||||
@ -112,6 +112,9 @@ void runTests() {
|
||||
OATPP_RUN_TEST(oatpp::test::parser::CaretTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::EnumTest);
|
||||
*/
|
||||
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::UnorderedSetTest);
|
||||
/*
|
||||
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::DeserializerTest);
|
||||
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::DTOMapperPerfTest);
|
||||
OATPP_RUN_TEST(oatpp::test::parser::json::mapping::DTOMapperTest);
|
||||
|
53
test/oatpp/parser/json/mapping/UnorderedSetTest.cpp
Normal file
53
test/oatpp/parser/json/mapping/UnorderedSetTest.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* 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 "UnorderedSetTest.hpp"
|
||||
|
||||
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
|
||||
|
||||
namespace oatpp { namespace test { namespace parser { namespace json { namespace mapping {
|
||||
|
||||
void UnorderedSetTest::onRun() {
|
||||
|
||||
oatpp::parser::json::mapping::ObjectMapper mapper;
|
||||
|
||||
{
|
||||
oatpp::UnorderedSet<oatpp::String> set = {"Hello", "World", "!"};
|
||||
auto json = mapper.writeToString(set);
|
||||
OATPP_LOGD(TAG, "json='%s'", json->c_str());
|
||||
}
|
||||
|
||||
{
|
||||
oatpp::String json = "[\"Hello\",\"World\",\"!\",\"Hello\",\"World\",\"!\"]";
|
||||
auto set = mapper.readFromString<oatpp::UnorderedSet<oatpp::String>>(json);
|
||||
OATPP_ASSERT(set);
|
||||
OATPP_ASSERT(set->size() == 3);
|
||||
for(auto& item : *set) {
|
||||
OATPP_LOGD(TAG, "item='%s'", item->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}}}}}
|
42
test/oatpp/parser/json/mapping/UnorderedSetTest.hpp
Normal file
42
test/oatpp/parser/json/mapping/UnorderedSetTest.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* 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_UnorderedSetTest_hpp
|
||||
#define oatpp_test_parser_json_mapping_UnorderedSetTest_hpp
|
||||
|
||||
#include "oatpp-test/UnitTest.hpp"
|
||||
|
||||
namespace oatpp { namespace test { namespace parser { namespace json { namespace mapping {
|
||||
|
||||
class UnorderedSetTest : public UnitTest{
|
||||
public:
|
||||
|
||||
UnorderedSetTest():UnitTest("TEST[parser::json::mapping::UnorderedSetTest]"){}
|
||||
void onRun() override;
|
||||
|
||||
};
|
||||
|
||||
}}}}}
|
||||
|
||||
#endif /* oatpp_test_parser_json_mapping_UnorderedSetTest_hpp */
|
Loading…
Reference in New Issue
Block a user