/src/oatpp/src/oatpp/json/ObjectMapper.hpp
Line | Count | Source |
1 | | /*************************************************************************** |
2 | | * |
3 | | * Project _____ __ ____ _ _ |
4 | | * ( _ ) /__\ (_ _)_| |_ _| |_ |
5 | | * )(_)( /(__)\ )( (_ _)(_ _) |
6 | | * (_____)(__)(__)(__) |_| |_| |
7 | | * |
8 | | * |
9 | | * Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com> |
10 | | * |
11 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
12 | | * you may not use this file except in compliance with the License. |
13 | | * You may obtain a copy of the License at |
14 | | * |
15 | | * http://www.apache.org/licenses/LICENSE-2.0 |
16 | | * |
17 | | * Unless required by applicable law or agreed to in writing, software |
18 | | * distributed under the License is distributed on an "AS IS" BASIS, |
19 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 | | * See the License for the specific language governing permissions and |
21 | | * limitations under the License. |
22 | | * |
23 | | ***************************************************************************/ |
24 | | |
25 | | #ifndef oatpp_json_ObjectMapper_hpp |
26 | | #define oatpp_json_ObjectMapper_hpp |
27 | | |
28 | | #include "./Serializer.hpp" |
29 | | #include "./Deserializer.hpp" |
30 | | |
31 | | #include "oatpp/data/mapping/ObjectToTreeMapper.hpp" |
32 | | #include "oatpp/data/mapping/TreeToObjectMapper.hpp" |
33 | | #include "oatpp/data/mapping/ObjectMapper.hpp" |
34 | | |
35 | | namespace oatpp { namespace json { |
36 | | |
37 | | /** |
38 | | * Json ObjectMapper. Serialized/Deserializes oatpp DTO objects to/from JSON. |
39 | | * See [Data Transfer Object(DTO) component](https://oatpp.io/docs/components/dto/). <br> |
40 | | * Extends &id:oatpp::base::Countable;, &id:oatpp::data::mapping::ObjectMapper;. |
41 | | */ |
42 | | class ObjectMapper : public oatpp::base::Countable, public oatpp::data::mapping::ObjectMapper { |
43 | | private: |
44 | 3.96k | static Info getMapperInfo() { |
45 | 3.96k | return Info("application", "json"); |
46 | 3.96k | } |
47 | | |
48 | | public: |
49 | | |
50 | | class DeserializerConfig { |
51 | | public: |
52 | | data::mapping::TreeToObjectMapper::Config mapper; |
53 | | Deserializer::Config json; |
54 | | }; |
55 | | |
56 | | public: |
57 | | |
58 | | class SerializerConfig { |
59 | | public: |
60 | | data::mapping::ObjectToTreeMapper::Config mapper; |
61 | | Serializer::Config json; |
62 | | }; |
63 | | |
64 | | private: |
65 | | void writeTree(data::stream::ConsistentOutputStream* stream, const data::mapping::Tree& tree, data::mapping::ErrorStack& errorStack) const; |
66 | | private: |
67 | | SerializerConfig m_serializerConfig; |
68 | | DeserializerConfig m_deserializerConfig; |
69 | | private: |
70 | | data::mapping::ObjectToTreeMapper m_objectToTreeMapper; |
71 | | data::mapping::TreeToObjectMapper m_treeToObjectMapper; |
72 | | public: |
73 | | |
74 | | ObjectMapper(const SerializerConfig& serializerConfig = {}, const DeserializerConfig& deserializerConfig = {}); |
75 | | |
76 | | void write(data::stream::ConsistentOutputStream* stream, const oatpp::Void& variant, data::mapping::ErrorStack& errorStack) const override; |
77 | | |
78 | | oatpp::Void read(oatpp::utils::parser::Caret& caret, const oatpp::Type* type, data::mapping::ErrorStack& errorStack) const override; |
79 | | |
80 | | const data::mapping::ObjectToTreeMapper& objectToTreeMapper() const; |
81 | | const data::mapping::TreeToObjectMapper& treeToObjectMapper() const; |
82 | | |
83 | | data::mapping::ObjectToTreeMapper& objectToTreeMapper(); |
84 | | data::mapping::TreeToObjectMapper& treeToObjectMapper(); |
85 | | |
86 | | const SerializerConfig& serializerConfig() const; |
87 | | const DeserializerConfig& deserializerConfig() const; |
88 | | |
89 | | SerializerConfig& serializerConfig(); |
90 | | DeserializerConfig& deserializerConfig(); |
91 | | |
92 | | }; |
93 | | |
94 | | }} |
95 | | |
96 | | #endif /* oatpp_json_ObjectMapper_hpp */ |