Merge pull request #248 from oatpp/finalize_object_wrapper_api

Finalize object wrapper api
This commit is contained in:
Leonid Stryzhevskyi 2020-05-23 04:29:32 +03:00 committed by GitHub
commit b969668779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 264 additions and 281 deletions

View File

@ -50,7 +50,7 @@ For more info see [Api Controller](https://oatpp.io/docs/components/api-controll
```cpp
ENDPOINT("PUT", "/users/{userId}", putUser,
PATH(Int64, userId),
BODY_DTO(UserDto, userDto))
BODY_DTO(Object<UserDto>, userDto))
{
userDto->id = userId;
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
@ -65,7 +65,7 @@ For more info see [Api Controller / CORS](https://oatpp.io/docs/components/api-c
ADD_CORS(putUser)
ENDPOINT("PUT", "/users/{userId}", putUser,
PATH(Int64, userId),
BODY_DTO(UserDto, userDto))
BODY_DTO(Object<UserDto>, userDto))
{
userDto->id = userId;
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
@ -82,7 +82,7 @@ using namespace oatpp::web::server::handler;
ENDPOINT("PUT", "/users/{userId}", putUser,
AUTHORIZATION(std::shared_ptr<DefaultBasicAuthorizationObject>, authObject),
PATH(Int64, userId),
BODY_DTO(UserDto, userDto))
BODY_DTO(Object<UserDto>, userDto))
{
OATPP_ASSERT_HTTP(authObject->userId == "Ivan" && authObject->password == "admin", Status::CODE_401, "Unauthorized");
userDto->id = userId;
@ -100,15 +100,15 @@ For more info see [Endpoint Annotation And API Documentation](https://oatpp.io/d
ENDPOINT_INFO(putUser) {
// general
info->summary = "Update User by userId";
info->addConsumes<UserDto>("application/json");
info->addResponse<UserDto>(Status::CODE_200, "application/json");
info->addConsumes<Object<UserDto>>("application/json");
info->addResponse<Object<UserDto>>(Status::CODE_200, "application/json");
info->addResponse<String>(Status::CODE_404, "text/plain");
// params specific
info->pathParams["userId"].description = "User Identifier";
}
ENDPOINT("PUT", "/users/{userId}", putUser,
PATH(Int64, userId),
BODY_DTO(UserDto, userDto))
BODY_DTO(Object<UserDto>, userDto))
{
userDto->id = userId;
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
@ -137,7 +137,7 @@ public:
```cpp
auto response = userService->getUserById(id);
auto user = response->readBodyToDto<dto::UserDto>(objectMapper);
auto user = response->readBodyToDto<oatpp::Object<UserDto>>(objectMapper);
```
### Object Mapping
@ -147,9 +147,9 @@ For more info see [Data Transfer Object (DTO)](https://oatpp.io/docs/components/
#### Declare DTO
```cpp
class UserDto : public oatpp::data::mapping::type::Object {
class UserDto : public oatpp::DTO {
DTO_INIT(UserDto, Object)
DTO_INIT(UserDto, DTO)
DTO_FIELD(Int64, id);
DTO_FIELD(String, name);

View File

@ -6,7 +6,7 @@ Please read carefully to prepare for migration.
Feel free to ask questions - [Chat on Gitter](https://gitter.im/oatpp-framework/Lobby)
Contents:
- [No More Explicit ObjectWrapper](#no-more-explicit-objectwrapper)
- [No More ObjectWrapper](#no-more-objectwrapper)
- [Object-Mapping Simplified Primitives](#object-mapping-simplified-primitives)
- [Object-Mapping std Collections](#object-mapping-std-collections)
- [Type oatpp::Any](#type-oatppany)
@ -14,52 +14,50 @@ Contents:
- [DTO - Hashcode & Equals](#dto-hashcode-and-equals)
- [DTO - Fields Annotation](#dto-fields-annotation)
## No More Explicit ObjectWrapper
## No More ObjectWrapper
Do not explicitly write `ObjectWrapper` for collections.
`ObjectWrapper` is a base-class for oatpp core types (`oatpp/core/Types.hpp`).
The explicit `::ObjectWrapper` qualifier is removed.
DTO:
### DTO:
```cpp
class MyDto : oatpp::Object {
class MyDto : oatpp::DTO { // <--- Notice the 'oatpp::DTO' now. NOT the 'oatpp::Object'
DTO_INIT(MyDto, Object)
DTO_INIT(MyDto, DTO)
DTO_FIELD(MyDto, nested);
DTO_FIELD(List<Any>, listOfAny);
DTO_FIELD(Object<MyDto>, nested); // <--- Notice the oatpp::Object<T> for Objects, instead of T::ObjectWrapper
DTO_FIELD(List<Any>, listOfAny); // <--- No '::ObjectWrapper' for collections.
DTO_FIELD(Fields<List<String>>, mapOfLists);
}
```
ApiController:
### ApiController:
```cpp
ENDPOINT("POST", "body-dto", postWithBody,
BODY_DTO(MyDto, body)) {
BODY_DTO(Object<MyDto>, body)) {
...
}
```
### Except for Cases
For `Object` in some cases, you still have to explicitly specify `ObjectWrapper` type.
Examples:
When declaring a variable or a function return type:
### ApiClient:
```cpp
/* function parameters and return types */
MyDto::ObjectWrapper foo(const MyDto::ObjectWrapper& parameter) {
API_CALL("POST", "body-dto", postWithBody, BODY_DTO(Object<MyDto>, body))
```
/* declaring a variable */
MyDto::ObjectWrapper myDto = MyDto::createShared();
### In Other Code-Blocks
auto myDto = MyDto::createShared(); // better.
```cpp
oatpp::Object<MyDto> myDto;
oatpp::List<oatpp::Object<MyDto>> listOfDtos;
return myDto;
}
...
auto myDto = objectMapper->readFromString<Object<MyDto>>(json);
auto listOfDtos = objectMapper->readFromString<List<Object<MyDto>>>(json);
```
## Object-Mapping Simplified Primitives
@ -82,11 +80,11 @@ Now `oatpp::<mapping-enabled-collections>` are based on `std::<collections>`
Example:
```cpp
oatpp::Vector<oatpp::String> vector = oatpp::Vector<oatpp::String>::createShared();
oatpp::List<oatpp::String> list = oatpp::List<oatpp::String>::createShared();
oatpp::UnorderedSet<oatpp::String> set = oatpp::UnorderedSet<oatpp::String>::createShared();
oatpp::Fields<oatpp::String> pairList= oatpp::Fields<oatpp::String>::createShared();
oatpp::UnorderedFields<oatpp::String> hashMap = oatpp::UnorderedFields<oatpp::String>::createShared();
oatpp::Vector<oatpp::String> vector({});
oatpp::List<oatpp::String> list({});
oatpp::UnorderedSet<oatpp::String> set({});
oatpp::Fields<oatpp::String> pairList({});
oatpp::UnorderedFields<oatpp::String> hashMap({});
oatpp::Vector<oatpp::String> vector = {"a", "b", "c"};
oatpp::List<oatpp::String> list = {"a", "b", "c"};

View File

@ -56,7 +56,7 @@
#define PATH(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_PATH, TYPE, (__VA_ARGS__))
#define QUERY(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_QUERY, TYPE, (__VA_ARGS__))
#define BODY(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_BODY, TYPE, (__VA_ARGS__))
#define BODY_DTO(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_BODY_DTO, TYPE::__Wrapper, (__VA_ARGS__))
#define BODY_DTO(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_BODY_DTO, TYPE, (__VA_ARGS__))
#define BODY_STRING(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_BODY_STRING, TYPE, (__VA_ARGS__))
#define AUTHORIZATION(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_AUTHORIZATION, TYPE, (__VA_ARGS__))
#define AUTHORIZATION_BASIC(TYPE, ...) OATPP_MACRO_API_CLIENT_PARAM(OATPP_MACRO_API_CLIENT_AUTHORIZATION_BASIC, TYPE, (__VA_ARGS__))

View File

@ -49,7 +49,7 @@ OATPP_MACRO_API_CONTROLLER_PARAM(OATPP_MACRO_API_CONTROLLER_QUERY, OATPP_MACRO_A
OATPP_MACRO_API_CONTROLLER_PARAM(OATPP_MACRO_API_CONTROLLER_BODY_STRING, OATPP_MACRO_API_CONTROLLER_BODY_STRING_INFO, TYPE, (__VA_ARGS__))
#define BODY_DTO(TYPE, ...) \
OATPP_MACRO_API_CONTROLLER_PARAM(OATPP_MACRO_API_CONTROLLER_BODY_DTO, OATPP_MACRO_API_CONTROLLER_BODY_DTO_INFO, TYPE::__Wrapper, (__VA_ARGS__))
OATPP_MACRO_API_CONTROLLER_PARAM(OATPP_MACRO_API_CONTROLLER_BODY_DTO, OATPP_MACRO_API_CONTROLLER_BODY_DTO_INFO, TYPE, (__VA_ARGS__))
//////////////////////////////////////////////////////////////////////////

View File

@ -36,8 +36,7 @@
public: \
typedef TYPE_NAME Z__CLASS; \
typedef TYPE_EXTEND Z__CLASS_EXTENDED; \
typedef oatpp::data::mapping::type::DTOWrapper<Z__CLASS> ObjectWrapper; \
typedef ObjectWrapper __Wrapper; \
typedef oatpp::data::mapping::type::DTOWrapper<Z__CLASS> Wrapper; \
private: \
static const char* Z__CLASS_TYPE_NAME() { \
return #TYPE_NAME; \
@ -52,8 +51,8 @@ public: \
TYPE_NAME() = default; \
\
template<typename ... Args> \
static ObjectWrapper createShared(Args... args){ \
return ObjectWrapper(std::make_shared<Z__CLASS>(args...), ObjectWrapper::Class::getType()); \
static Wrapper createShared(Args... args){ \
return Wrapper(std::make_shared<Z__CLASS>(args...), Wrapper::Class::getType()); \
}
// Fields
@ -71,7 +70,7 @@ static oatpp::data::mapping::type::Type::Property* Z__PROPERTY_SINGLETON_##NAME(
static oatpp::data::mapping::type::Type::Property* property = \
new oatpp::data::mapping::type::Type::Property(Z__PROPERTY_OFFSET_##NAME(), \
#NAME, \
TYPE::__Wrapper::Class::getType()); \
TYPE::Class::getType()); \
return property; \
} \
\
@ -80,12 +79,12 @@ static bool Z__PROPERTY_INIT_##NAME(... /* default initializer for all cases */)
return true; \
} \
\
static TYPE::__Wrapper Z__PROPERTY_INITIALIZER_PROXY_##NAME() { \
static TYPE Z__PROPERTY_INITIALIZER_PROXY_##NAME() { \
static bool initialized = Z__PROPERTY_INIT_##NAME(1 /* init info if found */); \
return TYPE::__Wrapper(); \
return TYPE(); \
} \
\
TYPE::__Wrapper NAME = Z__PROPERTY_INITIALIZER_PROXY_##NAME()
TYPE NAME = Z__PROPERTY_INITIALIZER_PROXY_##NAME()
#define OATPP_MACRO_DTO_FIELD_2(TYPE, NAME, QUALIFIER) \
\
@ -100,7 +99,7 @@ static oatpp::data::mapping::type::Type::Property* Z__PROPERTY_SINGLETON_##NAME(
static oatpp::data::mapping::type::Type::Property* property = \
new oatpp::data::mapping::type::Type::Property(Z__PROPERTY_OFFSET_##NAME(), \
QUALIFIER, \
TYPE::__Wrapper::Class::getType()); \
TYPE::Class::getType()); \
return property; \
} \
\
@ -109,12 +108,12 @@ static bool Z__PROPERTY_INIT_##NAME(... /* default initializer for all cases */)
return true; \
} \
\
static TYPE::__Wrapper Z__PROPERTY_INITIALIZER_PROXY_##NAME() { \
static TYPE Z__PROPERTY_INITIALIZER_PROXY_##NAME() { \
static bool initialized = Z__PROPERTY_INIT_##NAME(1 /* init info if found */); \
return TYPE::__Wrapper(); \
return TYPE(); \
} \
\
TYPE::__Wrapper NAME = Z__PROPERTY_INITIALIZER_PROXY_##NAME()
TYPE NAME = Z__PROPERTY_INITIALIZER_PROXY_##NAME()
/**
* Codegen macro to generate fields of DTO object.
@ -150,7 +149,7 @@ v_uint64 defaultHashCode() const override { \
return 1; \
} \
\
bool defaultEquals(const Object& other) const override { \
bool defaultEquals(const DTO& other) const override { \
return true; \
} \
\

View File

@ -102,9 +102,15 @@ namespace oatpp {
typedef oatpp::data::mapping::type::Boolean Boolean;
/**
* Mapping-Enabled Object. Base class for all DTO objects. &id:oatpp::data::mapping::type::Object;
* Base class for all DTO objects. &id:oatpp::data::mapping::type::DTO;
*/
typedef oatpp::data::mapping::type::Object Object;
typedef oatpp::data::mapping::type::DTO DTO;
/*
* Mapping-Enabled DTO Object.
*/
template <class T>
using Object = oatpp::data::mapping::type::DTOWrapper<T>;
/*
* Mapping-Enabled Enum. &id:oatpp::data::mapping::type::Enum;

View File

@ -102,30 +102,30 @@ public:
/**
* Deserialize object.
* If nullptr is returned - check caret.getError()
* @tparam Class - object class.
* @tparam Wrapper - ObjectWrapper type.
* @param caret - &id:oatpp::parser::Caret; over serialized buffer.
* @return - deserialized Object.
* @throws - depends on implementation.
*/
template<class Class>
typename Class::__Wrapper readFromCaret(oatpp::parser::Caret& caret) const {
auto type = Class::__Wrapper::Class::getType();
return read(caret, type).template staticCast<typename Class::__Wrapper>();
template<class Wrapper>
Wrapper readFromCaret(oatpp::parser::Caret& caret) const {
auto type = Wrapper::Class::getType();
return read(caret, type).template staticCast<Wrapper>();
}
/**
* Deserialize object.
* @tparam Class - object class.
* @tparam Wrapper - ObjectWrapper type.
* @param str - serialized data.
* @return - deserialized Object.
* @throws - &id:oatpp::parser::ParsingError;
* @throws - depends on implementation.
*/
template<class Class>
typename Class::__Wrapper readFromString(const oatpp::String& str) const {
auto type = Class::__Wrapper::Class::getType();
template<class Wrapper>
Wrapper readFromString(const oatpp::String& str) const {
auto type = Wrapper::Class::getType();
oatpp::parser::Caret caret(str);
auto result = read(caret, type).template staticCast<typename Class::__Wrapper>();
auto result = read(caret, type).template staticCast<Wrapper>();
if(!result) {
throw oatpp::parser::ParsingError(caret.getErrorMessage(), caret.getErrorCode(), caret.getPosition());
}

View File

@ -63,8 +63,6 @@ public:
};
class Any : public ObjectWrapper<AnyHandle, __class::Any>{
public:
typedef Any __Wrapper;
public:
Any();
@ -89,15 +87,15 @@ public:
const Type* getStoredType() const;
template<class WrapperType>
typename WrapperType::__Wrapper retrieve() const {
WrapperType retrieve() const {
if(m_ptr) {
if(m_ptr->type != WrapperType::__Wrapper::Class::getType()) {
if(m_ptr->type != WrapperType::Class::getType()) {
throw std::runtime_error("[oatpp::data::mapping::type::Any::retrieve()]: Error. The value type doesn't match.");
}
return typename WrapperType::__Wrapper(std::static_pointer_cast<typename WrapperType::__Wrapper::ObjectType>(m_ptr->ptr), m_ptr->type);
return WrapperType(std::static_pointer_cast<typename WrapperType::ObjectType>(m_ptr->ptr), m_ptr->type);
}

View File

@ -174,8 +174,6 @@ template<class T, class EnumInterpreter>
class EnumObjectWrapper : public ObjectWrapper<T, __class::Enum<T, EnumInterpreter>>{
template<class Type, class Interpreter>
friend class EnumObjectWrapper;
public:
typedef EnumObjectWrapper __Wrapper;
public:
typedef typename std::underlying_type<T>::type UnderlyingEnumType;
typedef T Z__EnumType;

View File

@ -86,7 +86,7 @@ public:
};
template<class T>
using List = ListObjectWrapper<typename T::__Wrapper, __class::List<typename T::__Wrapper>>;
using List = ListObjectWrapper<T, __class::List<T>>;
typedef ListObjectWrapper<type::Void, __class::AbstractList> AbstractList;

View File

@ -91,11 +91,60 @@ namespace __class {
}
/**
* ObjectWrapper for &l:DTO;. AKA `oatpp::Object<T>`.
* @tparam ObjT - class extended from &l:DTO;.
*/
template<class ObjT>
class DTOWrapper : public ObjectWrapper<ObjT, __class::Object<ObjT>> {
public:
typedef ObjT TemplateObjectType;
typedef __class::Object<ObjT> TemplateObjectClass;
public:
OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(DTOWrapper, TemplateObjectType, TemplateObjectClass)
static DTOWrapper createShared() {
return std::make_shared<TemplateObjectType>();
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
inline bool operator == (T){
return this->m_ptr.get() == nullptr;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
inline bool operator != (T){
return this->m_ptr.get() != nullptr;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, DTOWrapper>::value, void>::type
>
inline bool operator == (const T &other) const {
if(this->m_ptr.get() == other.m_ptr.get()) return true;
if(!this->m_ptr || !other.m_ptr) return false;
return *this->m_ptr == *other.m_ptr;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, DTOWrapper>::value, void>::type
>
inline bool operator != (const T &other) const {
return !operator == (other);
}
};
/**
* Base class for all DTO objects.
* For more info about Data Transfer Object (DTO) see [Data Transfer Object (DTO)](https://oatpp.io/docs/components/dto/).
*/
class Object : public oatpp::base::Countable {
class DTO : public oatpp::base::Countable {
template<class T>
friend class __class::Object;
public:
@ -114,6 +163,9 @@ public:
typedef oatpp::data::mapping::type::Float64 Float64;
typedef oatpp::data::mapping::type::Boolean Boolean;
template <class T>
using Object = DTOWrapper<T>;
template <class T>
using Enum = oatpp::data::mapping::type::Enum<T>;
@ -150,7 +202,7 @@ public:
return (v_uint64) reinterpret_cast<v_buff_usize>(this);
}
virtual bool defaultEquals(const Object& other) const {
virtual bool defaultEquals(const DTO& other) const {
return this == &other;
}
@ -158,56 +210,11 @@ public:
return defaultHashCode();
}
bool operator==(const Object& other) const {
bool operator==(const DTO& other) const {
return defaultEquals(other);
}
};
template<class ObjT>
class DTOWrapper : public ObjectWrapper<ObjT, __class::Object<ObjT>> {
public:
typedef ObjT TemplateObjectType;
typedef __class::Object<ObjT> TemplateObjectClass;
public:
OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(DTOWrapper, TemplateObjectType, TemplateObjectClass)
static DTOWrapper createShared() {
return std::make_shared<TemplateObjectType>();
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
inline bool operator == (T){
return this->m_ptr.get() == nullptr;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
inline bool operator != (T){
return this->m_ptr.get() != nullptr;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, DTOWrapper>::value, void>::type
>
inline bool operator == (const T &other) const {
if(this->m_ptr.get() == other.m_ptr.get()) return true;
if(!this->m_ptr || !other.m_ptr) return false;
return *this->m_ptr == *other.m_ptr;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, DTOWrapper>::value, void>::type
>
inline bool operator != (const T &other) const {
return !operator == (other);
}
};
}}}}

View File

@ -112,14 +112,7 @@ OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(PairListObjectWrapper, TemplateObjectType,
};
template<class Key, class Value>
using PairList = PairListObjectWrapper<
typename Key::__Wrapper,
typename Value::__Wrapper,
__class::PairList<
typename Key::__Wrapper,
typename Value::__Wrapper
>
>;
using PairList = PairListObjectWrapper<Key, Value, __class::PairList<Key, Value>>;
namespace __class {

View File

@ -60,8 +60,6 @@ namespace __class {
* Mapping-enables String is &id:type::ObjectWrapper; over &id:oatpp::base::StrBuffer;
*/
class String : public type::ObjectWrapper<base::StrBuffer, __class::String> {
public:
typedef String __Wrapper;
public:
String(const std::shared_ptr<base::StrBuffer>& ptr, const type::Type* const valueType);
public:

View File

@ -99,11 +99,6 @@ protected:
std::shared_ptr<T> m_ptr;
public:
/**
* Convenience self-typedef.
*/
typedef ObjectWrapper __Wrapper;
/**
* Static object type
*/
@ -389,8 +384,6 @@ public:
};
#define OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(WRAPPER_NAME, OBJECT_TYPE, OBJECT_CLASS) \
public:\
typedef WRAPPER_NAME __Wrapper; \
public: \
WRAPPER_NAME(const std::shared_ptr<OBJECT_TYPE>& ptr, const type::Type* const valueType) \
: type::ObjectWrapper<OBJECT_TYPE, OBJECT_CLASS>(ptr, valueType) \

View File

@ -85,14 +85,7 @@ OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(UnorderedMapObjectWrapper, TemplateObjectTy
};
template<class Key, class Value>
using UnorderedMap = UnorderedMapObjectWrapper<
typename Key::__Wrapper,
typename Value::__Wrapper,
__class::UnorderedMap<
typename Key::__Wrapper,
typename Value::__Wrapper
>
>;
using UnorderedMap = UnorderedMapObjectWrapper<Key, Value, __class::UnorderedMap<Key, Value>>;
namespace __class {

View File

@ -88,7 +88,7 @@ OATPP_DEFINE_OBJECT_WRAPPER_DEFAULTS(UnorderedSetObjectWrapper, TemplateObjectTy
};
template<class T>
using UnorderedSet = UnorderedSetObjectWrapper<typename T::__Wrapper, __class::UnorderedSet<typename T::__Wrapper>>;
using UnorderedSet = UnorderedSetObjectWrapper<T, __class::UnorderedSet<T>>;
typedef UnorderedSetObjectWrapper<type::Void, __class::AbstractUnorderedSet> AbstractUnorderedSet;

View File

@ -84,7 +84,7 @@ public:
};
template<class T>
using Vector = VectorObjectWrapper<typename T::__Wrapper, __class::Vector<typename T::__Wrapper>>;
using Vector = VectorObjectWrapper<T, __class::Vector<T>>;
typedef VectorObjectWrapper<type::Void, __class::AbstractVector> AbstractVector;

View File

@ -43,7 +43,6 @@ public:
typedef oatpp::data::mapping::type::Type::Property Property;
typedef oatpp::data::mapping::type::Type::Properties Properties;
typedef oatpp::data::mapping::type::Object Object;
typedef oatpp::String String;
public:

View File

@ -153,7 +153,7 @@ void Serializer::serializeObject(Serializer* serializer,
bool first = true;
auto fields = polymorph.valueType->propertiesGetter()->getList();
Object* object = static_cast<Object*>(polymorph.get());
oatpp::DTO* object = static_cast<oatpp::DTO*>(polymorph.get());
for (auto const& field : fields) {

View File

@ -41,7 +41,6 @@ public:
typedef oatpp::data::mapping::type::Type::Property Property;
typedef oatpp::data::mapping::type::Type::Properties Properties;
typedef oatpp::data::mapping::type::Object Object;
typedef oatpp::String String;
public:
/**

View File

@ -136,6 +136,9 @@ public:
template <class T>
using Enum = oatpp::data::mapping::type::Enum<T>;
template <class T>
using Object = oatpp::Object<T>;
public:
/**

View File

@ -41,8 +41,8 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac
class BodyDecoder {
private:
template<class Type>
class ToDtoDecoder : public oatpp::async::CoroutineWithResult<ToDtoDecoder<Type>, const typename Type::ObjectWrapper&> {
template<class Wrapper>
class ToDtoDecoder : public oatpp::async::CoroutineWithResult<ToDtoDecoder<Wrapper>, const Wrapper&> {
private:
const BodyDecoder* m_decoder;
Headers m_headers;
@ -69,7 +69,7 @@ private:
oatpp::async::Action onDecoded() {
auto body = m_outputStream->toString();
oatpp::parser::Caret caret(body);
auto dto = m_objectMapper->readFromCaret<Type>(caret);
auto dto = m_objectMapper->readFromCaret<Wrapper>(caret);
if(caret.hasError()) {
return this->template error<oatpp::async::Error>(caret.getErrorMessage());
}
@ -142,18 +142,18 @@ public:
/**
* Same as &l:BodyDecoder::decodeToDto (); but Async.
* @tparam DtoType - DTO object type.
* @tparam Wrapper - ObjectWrapper type.
* @param headers - Headers map. &id:oatpp::web::protocol::http::Headers;.
* @param bodyStream - `std::shared_ptr` to &id:oatpp::data::stream::InputStream;.
* @param objectMapper - `std::shared_ptr` to &id:oatpp::data::mapping::ObjectMapper;.
* @return - &id:oatpp::async::CoroutineStarterForResult;.
*/
template<class DtoType>
oatpp::async::CoroutineStarterForResult<const typename DtoType::ObjectWrapper&>
template<class Wrapper>
oatpp::async::CoroutineStarterForResult<const Wrapper&>
decodeToDtoAsync(const Headers& headers,
const std::shared_ptr<data::stream::InputStream>& bodyStream,
const std::shared_ptr<data::mapping::ObjectMapper>& objectMapper) const {
return ToDtoDecoder<DtoType>::startForResult(this, headers, bodyStream, objectMapper);
return ToDtoDecoder<Wrapper>::startForResult(this, headers, bodyStream, objectMapper);
}
};

View File

@ -194,13 +194,13 @@ public:
/**
* Transfer body to String and parse it as DTO
* @tparam Type
* @tparam Wrapper - ObjectWrapper type.
* @param objectMapper
* @return DTO
*/
template<class Type>
typename Type::__Wrapper readBodyToDto(data::mapping::ObjectMapper* objectMapper) const {
return objectMapper->readFromString<Type>(m_bodyDecoder->decodeToString(m_headers, m_bodyStream.get()));
template<class Wrapper>
Wrapper readBodyToDto(data::mapping::ObjectMapper* objectMapper) const {
return objectMapper->readFromString<Wrapper>(m_bodyDecoder->decodeToString(m_headers, m_bodyStream.get()));
}
// Async
@ -228,14 +228,14 @@ public:
/**
* Transfer body to String and parse it as DTO
* @tparam DtoType - DTO object type.
* @tparam Wrapper - DTO `ObjectWrapper`.
* @param objectMapper
* @return - &id:oatpp::async::CoroutineStarterForResult;.
*/
template<class DtoType>
oatpp::async::CoroutineStarterForResult<const typename DtoType::__Wrapper&>
template<class Wrapper>
oatpp::async::CoroutineStarterForResult<const Wrapper&>
readBodyToDtoAsync(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return m_bodyDecoder->decodeToDtoAsync<DtoType>(m_headers, m_bodyStream, objectMapper);
return m_bodyDecoder->decodeToDtoAsync<Wrapper>(m_headers, m_bodyStream, objectMapper);
}
};

View File

@ -179,14 +179,14 @@ public:
/**
* Same as &l:Response::readBodyToDto (); but Async.
* @tparam DtoType - DTO object type.
* @tparam Wrapper - ObjectWrapper type.
* @param objectMapper - `std::shared_ptr` to &id:oatpp::data::mapping::ObjectMapper;.
* @return - &id:oatpp::async::CoroutineStarterForResult;.
*/
template<class DtoType>
oatpp::async::CoroutineStarterForResult<const typename DtoType::ObjectWrapper&>
template<class Wrapper>
oatpp::async::CoroutineStarterForResult<const Wrapper&>
readBodyToDtoAsync(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
return m_bodyDecoder->decodeToDtoAsync<DtoType>(m_headers, m_bodyStream, objectMapper);
return m_bodyDecoder->decodeToDtoAsync<Wrapper>(m_headers, m_bodyStream, objectMapper);
}
};

View File

@ -188,6 +188,9 @@ public:
*/
typedef std::function<std::shared_ptr<Endpoint::Info>()> EndpointInfoBuilder;
template <class T>
using Object = oatpp::Object<T>;
template <class T>
using List = oatpp::List<T>;

View File

@ -96,7 +96,7 @@ public:
*/
template<class T>
Param& add(const oatpp::String& name) {
return add(name, T::__Wrapper::Class::getType());
return add(name, T::Class::getType());
}
/**
@ -218,21 +218,21 @@ public:
* @tparam T
* @param contentType
*/
template<class T>
template<class Wrapper>
void addConsumes(const oatpp::String& contentType) {
consumes.push_back({contentType, T::__Wrapper::Class::getType()});
consumes.push_back({contentType, Wrapper::Class::getType()});
}
/**
* Add response info to endpoint
* @tparam T
* @tparam Wrapper
* @param status
* @param contentType
* @param responseDescription
*/
template<class T>
template<class Wrapper>
void addResponse(const oatpp::web::protocol::http::Status& status, const oatpp::String& contentType, const oatpp::String& responseDescription = oatpp::String()) {
responses[status] = {contentType, T::__Wrapper::Class::getType(), responseDescription.get() == nullptr ? status.description : responseDescription};
responses[status] = {contentType, Wrapper::Class::getType(), responseDescription.get() == nullptr ? status.description : responseDescription};
}
/**

View File

@ -35,17 +35,17 @@ namespace {
#include OATPP_CODEGEN_BEGIN(DTO)
class Dto1 : public oatpp::Object {
DTO_INIT(Dto1, Object);
class Dto1 : public oatpp::DTO {
DTO_INIT(Dto1, DTO);
};
class Dto2 : public oatpp::Object {
DTO_INIT(Dto2, Object);
class Dto2 : public oatpp::DTO {
DTO_INIT(Dto2, DTO);
};
class Test : public oatpp::Object {
class Test : public oatpp::DTO {
DTO_INIT(Test, Object);
DTO_INIT(Test, DTO);
DTO_FIELD(oatpp::Any, any);
@ -110,12 +110,12 @@ void AnyTest::onRun() {
oatpp::Any any(Dto1::createShared());
OATPP_ASSERT(any);
OATPP_ASSERT(any.valueType == oatpp::data::mapping::type::__class::Any::getType());
OATPP_ASSERT(any.getStoredType() == Dto1::ObjectWrapper::Class::getType());
OATPP_ASSERT(any.getStoredType() == Object<Dto1>::Class::getType());
bool wasError = false;
try {
auto obj = any.retrieve<Dto2>(); // wrong object
auto obj = any.retrieve<oatpp::Object<Dto2>>(); // wrong object
} catch (std::runtime_error& e) {
wasError = true;
}

View File

@ -37,13 +37,13 @@ namespace {
#include OATPP_CODEGEN_BEGIN(DTO)
class Dto0 : public oatpp::Object {
DTO_INIT(Dto0, Object)
class Dto0 : public oatpp::DTO {
DTO_INIT(Dto0, DTO)
};
class DtoA : public oatpp::Object {
class DtoA : public oatpp::DTO {
DTO_INIT(DtoA, Object)
DTO_INIT(DtoA, DTO)
DTO_FIELD_INFO(id) {
info->description = "identifier";
@ -121,7 +121,7 @@ void ObjectTest::onRun() {
{
OATPP_LOGI(TAG, "Test Meta 1...");
auto type = DtoA::ObjectWrapper::Class::getType();
auto type = Object<DtoA>::Class::getType();
const auto& propsMap = type->propertiesGetter()->getMap();
OATPP_ASSERT(propsMap.size() == 1);
@ -136,7 +136,7 @@ void ObjectTest::onRun() {
{
OATPP_LOGI(TAG, "Test Meta 2...");
auto type = DtoB::ObjectWrapper::Class::getType();
auto type = Object<DtoB>::Class::getType();
const auto& propsMap = type->propertiesGetter()->getMap();
OATPP_ASSERT(propsMap.size() == 2);
@ -158,7 +158,7 @@ void ObjectTest::onRun() {
{
OATPP_LOGI(TAG, "Test 1...");
DtoA::ObjectWrapper a;
Object<DtoA> a;
OATPP_ASSERT(!a);
OATPP_ASSERT(a == nullptr);
OATPP_ASSERT(a.valueType->classId.id == oatpp::data::mapping::type::__class::AbstractObject::CLASS_ID.id);
@ -167,8 +167,8 @@ void ObjectTest::onRun() {
{
OATPP_LOGI(TAG, "Test 2...");
DtoA::ObjectWrapper a;
DtoA::ObjectWrapper b;
Object<DtoA> a;
Object<DtoA> b;
OATPP_ASSERT(a == b);
OATPP_LOGI(TAG, "OK");
}
@ -176,11 +176,11 @@ void ObjectTest::onRun() {
{
OATPP_LOGI(TAG, "Test 3...");
auto a = DtoA::createShared();
DtoA::ObjectWrapper b;
Object<DtoA> b;
OATPP_ASSERT(a != b);
OATPP_ASSERT(b != a);
auto ohc = a->hashCode();
auto whc = std::hash<DtoA::ObjectWrapper>{}(a);
auto whc = std::hash<oatpp::Object<DtoA>>{}(a);
OATPP_ASSERT(ohc == whc);
OATPP_LOGI(TAG, "OK");
}
@ -285,7 +285,7 @@ void ObjectTest::onRun() {
a->id = "1";
e->id = "1";
oatpp::UnorderedSet<DtoB> set = {a, b, c, d, e};
oatpp::UnorderedSet<oatpp::Object<DtoB>> set = {a, b, c, d, e};
OATPP_ASSERT(set->size() == 2);
OATPP_ASSERT(set[a] == true);

View File

@ -34,9 +34,9 @@ namespace {
#include OATPP_CODEGEN_BEGIN(DTO)
class TestDto : public oatpp::Object {
class TestDto : public oatpp::DTO {
DTO_INIT(TestDto, Object);
DTO_INIT(TestDto, DTO);
DTO_FIELD(String, field_string);
DTO_FIELD(Int8, field_int8);
@ -56,7 +56,7 @@ namespace {
DTO_FIELD(Fields<String>, field_map_string_string);
DTO_FIELD(TestDto, obj1);
DTO_FIELD(Object<TestDto>, obj1);
};

View File

@ -44,15 +44,15 @@ typedef oatpp::parser::json::mapping::Deserializer Deserializer;
#include OATPP_CODEGEN_BEGIN(DTO)
class Test1 : public oatpp::data::mapping::type::Object {
class Test1 : public oatpp::DTO {
DTO_INIT(Test1, Object)
DTO_INIT(Test1, DTO)
DTO_FIELD(String, field_string);
DTO_FIELD(Int32, field_int32);
DTO_FIELD(List<Int32>, field_list);
static ObjectWrapper createTestInstance(){
static Wrapper createTestInstance(){
auto result = Test1::createShared();
result->field_string = "String Field";
result->field_int32 = 5;
@ -92,7 +92,7 @@ void DTOMapperPerfTest::onRun() {
oatpp::parser::Caret caret(test1_Text);
for(v_int32 i = 0; i < numIterations; i ++) {
caret.setPosition(0);
mapper->readFromCaret<Test1>(caret);
mapper->readFromCaret<oatpp::Object<Test1>>(caret);
}
}

View File

@ -40,25 +40,25 @@ namespace {
#include OATPP_CODEGEN_BEGIN(DTO)
class TestChild : public oatpp::Object {
class TestChild : public oatpp::DTO {
DTO_INIT(TestChild, Object)
static ObjectWrapper createShared(const char* name, const char* secondName){
auto result = createShared();
result->name = name;
result->secondName = secondName;
return result;
}
DTO_INIT(TestChild, DTO)
DTO_FIELD(String, name) = "Name";
DTO_FIELD(String, secondName) = "Second Name";
public:
TestChild(const char* pName, const char* pSecondName)
: name(pName)
, secondName(pSecondName)
{}
};
class Test : public oatpp::Object {
class Test : public oatpp::DTO {
DTO_INIT(Test, Object)
DTO_INIT(Test, DTO)
DTO_FIELD(String, field_string, "string-field-name-qualifier");
DTO_FIELD(Int32, field_int32, "int32-field-name-qualifier");
@ -67,36 +67,36 @@ class Test : public oatpp::Object {
DTO_FIELD(Float64, field_float64);
DTO_FIELD(Boolean, field_boolean);
DTO_FIELD(List<String>, field_list_string) = List<String>::createShared();
DTO_FIELD(List<Int32>, field_list_int32) = List<Int32>::createShared();
DTO_FIELD(List<Int64>, field_list_int64) = List<Int64>::createShared();
DTO_FIELD(List<Float32>, field_list_float32) = List<Float32>::createShared();
DTO_FIELD(List<Float64>, field_list_float64) = List<Float64>::createShared();
DTO_FIELD(List<Boolean>, field_list_boolean) = List<Boolean>::createShared();
DTO_FIELD(List<String>, field_list_string) = {};
DTO_FIELD(List<Int32>, field_list_int32) = {};
DTO_FIELD(List<Int64>, field_list_int64) = {};
DTO_FIELD(List<Float32>, field_list_float32) = {};
DTO_FIELD(List<Float64>, field_list_float64) = {};
DTO_FIELD(List<Boolean>, field_list_boolean) = {};
DTO_FIELD(List<TestChild>, field_list_object) = List<TestChild>::createShared();
DTO_FIELD(List<List<TestChild>>, field_list_list_object) = List<List<TestChild>>::createShared();
DTO_FIELD(List<Object<TestChild>>, field_list_object) = {};
DTO_FIELD(List<List<Object<TestChild>>>, field_list_list_object) = {};
DTO_FIELD(Vector<String>, field_vector);
DTO_FIELD(Fields<String>, field_fields);
DTO_FIELD(UnorderedFields<String>, field_unordered_fields);
DTO_FIELD(Test, obj1);
DTO_FIELD(TestChild, child1);
DTO_FIELD(Object<Test>, obj1);
DTO_FIELD(Object<TestChild>, child1);
};
class TestAny : public oatpp::Object {
class TestAny : public oatpp::DTO {
DTO_INIT(TestAny, Object)
DTO_INIT(TestAny, DTO)
DTO_FIELD(List<Any>, anyList) = List<Any>::createShared();
};
class TestAnyNested : public oatpp::Object {
class TestAnyNested : public oatpp::DTO {
DTO_INIT(TestAnyNested, Object)
DTO_INIT(TestAnyNested, DTO)
DTO_FIELD(String, f1) = "Field_1";
DTO_FIELD(String, f2) = "Field_2";
@ -112,7 +112,7 @@ void DTOMapperTest::onRun(){
auto mapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
mapper->getSerializer()->getConfig()->useBeautifier = true;
Test::ObjectWrapper test1 = Test::createShared();
auto test1 = Test::createShared();
test1->field_string = "string value";
test1->field_int32 = 32;
@ -159,9 +159,9 @@ void DTOMapperTest::onRun(){
test1->field_list_object->push_back(TestChild::createShared("child", "2"));
test1->field_list_object->push_back(TestChild::createShared("child", "3"));
auto l1 = oatpp::List<TestChild>::createShared();
auto l2 = oatpp::List<TestChild>::createShared();
auto l3 = oatpp::List<TestChild>::createShared();
auto l1 = oatpp::List<oatpp::Object<TestChild>>::createShared();
auto l2 = oatpp::List<oatpp::Object<TestChild>>::createShared();
auto l3 = oatpp::List<oatpp::Object<TestChild>>::createShared();
l1->push_back(TestChild::createShared("list_1", "item_1"));
l1->push_back(TestChild::createShared("list_1", "item_2"));
@ -220,7 +220,7 @@ void DTOMapperTest::onRun(){
OATPP_LOGV(TAG, "...");
oatpp::parser::Caret caret(result);
auto obj = mapper->readFromCaret<Test>(caret);
auto obj = mapper->readFromCaret<oatpp::Object<Test>>(caret);
OATPP_ASSERT(obj->field_string);
OATPP_ASSERT(obj->field_string == test1->field_string);
@ -270,9 +270,6 @@ void DTOMapperTest::onRun(){
{
TestAny::ObjectWrapper::__Wrapper objOW1;
TestAny::__Wrapper objOW2;
auto obj = TestAny::createShared();
obj->anyList = {
oatpp::String("Hello Any!!!"),

View File

@ -32,19 +32,18 @@ namespace oatpp { namespace test { namespace parser { namespace json { namespace
namespace {
#include OATPP_CODEGEN_BEGIN(DTO)
typedef oatpp::data::mapping::type::Object DTO;
typedef oatpp::parser::Caret ParsingCaret;
typedef oatpp::parser::json::mapping::Serializer Serializer;
typedef oatpp::parser::json::mapping::Deserializer Deserializer;
class EmptyDto : public DTO {
class EmptyDto : public oatpp::DTO {
DTO_INIT(EmptyDto, DTO)
};
class Test1 : public DTO {
class Test1 : public oatpp::DTO {
DTO_INIT(Test1, DTO)
@ -52,7 +51,7 @@ class Test1 : public DTO {
};
class Test2 : public DTO {
class Test2 : public oatpp::DTO {
DTO_INIT(Test2, DTO)
@ -60,7 +59,7 @@ class Test2 : public DTO {
};
class Test3 : public DTO {
class Test3 : public oatpp::DTO {
DTO_INIT(Test3, DTO)
@ -68,13 +67,13 @@ class Test3 : public DTO {
};
class Test4 : public DTO {
class Test4 : public oatpp::DTO {
DTO_INIT(Test4, DTO)
DTO_FIELD(EmptyDto, object);
DTO_FIELD(List<EmptyDto>, list);
DTO_FIELD(Fields<EmptyDto>, map);
DTO_FIELD(Object<EmptyDto>, object);
DTO_FIELD(List<Object<EmptyDto>>, list);
DTO_FIELD(Fields<Object<EmptyDto>>, map);
};
@ -86,74 +85,74 @@ void DeserializerTest::onRun(){
auto mapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
auto obj1 = mapper->readFromString<Test1>("{}");
auto obj1 = mapper->readFromString<oatpp::Object<Test1>>("{}");
OATPP_ASSERT(obj1);
OATPP_ASSERT(!obj1->strF);
obj1 = mapper->readFromString<Test1>("{\"strF\":\"value1\"}");
obj1 = mapper->readFromString<oatpp::Object<Test1>>("{\"strF\":\"value1\"}");
OATPP_ASSERT(obj1);
OATPP_ASSERT(obj1->strF);
OATPP_ASSERT(obj1->strF->equals("value1"));
obj1 = mapper->readFromString<Test1>("{\n\r\t\f\"strF\"\n\r\t\f:\n\r\t\f\"value1\"\n\r\t\f}");
obj1 = mapper->readFromString<oatpp::Object<Test1>>("{\n\r\t\f\"strF\"\n\r\t\f:\n\r\t\f\"value1\"\n\r\t\f}");
OATPP_ASSERT(obj1);
OATPP_ASSERT(obj1->strF);
OATPP_ASSERT(obj1->strF->equals("value1"));
auto obj2 = mapper->readFromString<Test2>("{\"int32F\": null}");
auto obj2 = mapper->readFromString<oatpp::Object<Test2>>("{\"int32F\": null}");
OATPP_ASSERT(obj2);
OATPP_ASSERT(!obj2->int32F);
obj2 = mapper->readFromString<Test2>("{\"int32F\": 32}");
obj2 = mapper->readFromString<oatpp::Object<Test2>>("{\"int32F\": 32}");
OATPP_ASSERT(obj2);
OATPP_ASSERT(obj2->int32F == 32);
obj2 = mapper->readFromString<Test2>("{\"int32F\": -32}");
obj2 = mapper->readFromString<oatpp::Object<Test2>>("{\"int32F\": -32}");
OATPP_ASSERT(obj2);
OATPP_ASSERT(obj2->int32F == -32);
auto obj3 = mapper->readFromString<Test3>("{\"float32F\": null}");
auto obj3 = mapper->readFromString<oatpp::Object<Test3>>("{\"float32F\": null}");
OATPP_ASSERT(obj3);
OATPP_ASSERT(!obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 32}");
obj3 = mapper->readFromString<oatpp::Object<Test3>>("{\"float32F\": 32}");
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F == 32);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 1.32e1}");
obj3 = mapper->readFromString<oatpp::Object<Test3>>("{\"float32F\": 1.32e1}");
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 1.32e+1 }");
obj3 = mapper->readFromString<oatpp::Object<Test3>>("{\"float32F\": 1.32e+1 }");
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": 1.32e-1 }");
obj3 = mapper->readFromString<oatpp::Object<Test3>>("{\"float32F\": 1.32e-1 }");
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": -1.32E-1 }");
obj3 = mapper->readFromString<oatpp::Object<Test3>>("{\"float32F\": -1.32E-1 }");
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
obj3 = mapper->readFromString<Test3>("{\"float32F\": -1.32E1 }");
obj3 = mapper->readFromString<oatpp::Object<Test3>>("{\"float32F\": -1.32E1 }");
OATPP_ASSERT(obj3);
OATPP_ASSERT(obj3->float32F);
auto list = mapper->readFromString<Test1::List<Test1::Int32>>("[1, 2, 3]");
auto list = mapper->readFromString<oatpp::List<oatpp::Int32>>("[1, 2, 3]");
OATPP_ASSERT(list);
OATPP_ASSERT(list->size() == 3);
OATPP_ASSERT(list[0] == 1);
@ -162,14 +161,14 @@ void DeserializerTest::onRun(){
// Empty test
auto obj4 = mapper->readFromString<Test4>("{\"object\": {}, \"list\": [], \"map\": {}}");
auto obj4 = mapper->readFromString<oatpp::Object<Test4>>("{\"object\": {}, \"list\": [], \"map\": {}}");
OATPP_ASSERT(obj4);
OATPP_ASSERT(obj4->object);
OATPP_ASSERT(obj4->list);
OATPP_ASSERT(obj4->list->size() == 0);
OATPP_ASSERT(obj4->map->size() == 0);
obj4 = mapper->readFromString<Test4>("{\"object\": {\n\r\t}, \"list\": [\n\r\t], \"map\": {\n\r\t}}");
obj4 = mapper->readFromString<oatpp::Object<Test4>>("{\"object\": {\n\r\t}, \"list\": [\n\r\t], \"map\": {\n\r\t}}");
OATPP_ASSERT(obj4);
OATPP_ASSERT(obj4->object);
OATPP_ASSERT(obj4->list);

View File

@ -42,9 +42,9 @@ ENUM(Enum1, v_int32,
VALUE(V3, 30, "enum1-v3")
);
class DTO1 : public oatpp::Object {
class DTO1 : public oatpp::DTO {
DTO_INIT(DTO1, Object)
DTO_INIT(DTO1, DTO)
DTO_FIELD(Enum<Enum1>::AsString, enum1);

View File

@ -184,10 +184,10 @@ public:
Action onResponse(const std::shared_ptr<IncomingResponse>& response) {
OATPP_ASSERT(response->getStatusCode() == 200 && "ClientCoroutine_postBodyAsync");
return response->readBodyToDtoAsync<app::TestDto>(objectMapper).callbackTo(&ClientCoroutine_postBodyAsync::onBodyRead);
return response->readBodyToDtoAsync<oatpp::Object<app::TestDto>>(objectMapper).callbackTo(&ClientCoroutine_postBodyAsync::onBodyRead);
}
Action onBodyRead(const app::TestDto::ObjectWrapper& body) {
Action onBodyRead(const oatpp::Object<app::TestDto>& body) {
OATPP_ASSERT(body);
OATPP_ASSERT(body->testValue == "my_test_body");
++ SUCCESS_COUNTER;

View File

@ -175,7 +175,7 @@ void FullAsyncTest::onRun() {
{ // test GET with path parameter
auto response = client->getWithParams("my_test_param-Async", connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_param-Async");
}
@ -183,7 +183,7 @@ void FullAsyncTest::onRun() {
{ // test GET with header parameter
auto response = client->getWithHeaders("my_test_header-Async", connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_header-Async");
}
@ -191,7 +191,7 @@ void FullAsyncTest::onRun() {
{ // test POST with body
auto response = client->postBody("my_test_body-Async", connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_body-Async");
}

View File

@ -251,7 +251,7 @@ void FullTest::onRun() {
{ // test GET with path parameter
auto response = client->getWithParams("my_test_param", connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_param");
}
@ -259,7 +259,7 @@ void FullTest::onRun() {
{ // test GET with query parameters
auto response = client->getWithQueries("oatpp", 1, connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "name=oatpp&age=1");
}
@ -267,7 +267,7 @@ void FullTest::onRun() {
{ // test GET with query parameters
auto response = client->getWithQueriesMap("value1", 32, 0.32f, connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testMap);
OATPP_ASSERT(dto->testMap->size() == 3);
@ -279,7 +279,7 @@ void FullTest::onRun() {
{ // test GET with header parameter
auto response = client->getWithHeaders("my_test_header", connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_header");
}
@ -287,7 +287,7 @@ void FullTest::onRun() {
{ // test POST with body
auto response = client->postBody("my_test_body", connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dto = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dto = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_body");
}
@ -297,7 +297,7 @@ void FullTest::onRun() {
dtoIn->testValueInt = i;
auto response = client->postBodyDto(dtoIn, connection);
OATPP_ASSERT(response->getStatusCode() == 200);
auto dtoOut = response->readBodyToDto<app::TestDto>(objectMapper.get());
auto dtoOut = response->readBodyToDto<oatpp::Object<app::TestDto>>(objectMapper.get());
OATPP_ASSERT(dtoOut);
OATPP_ASSERT(dtoOut->testValueInt == i);
}

View File

@ -55,7 +55,7 @@ public:
API_CALL("GET", "queries/map", getWithQueriesMap, QUERY(String, key1), QUERY(Int32, key2), QUERY(Float32, key3))
API_CALL("GET", "headers", getWithHeaders, HEADER(String, param, "X-TEST-HEADER"))
API_CALL("POST", "body", postBody, BODY_STRING(String, body))
API_CALL("POST", "body-dto", postBodyDto, BODY_DTO(TestDto, body))
API_CALL("POST", "body-dto", postBodyDto, BODY_DTO(Object<TestDto>, body))
API_CALL("GET", "enum/as-string", getHeaderEnumAsString, HEADER(Enum<AllowedPathParams>::AsString, enumValue, "enum"))
API_CALL("GET", "enum/as-number", getHeaderEnumAsNumber, HEADER(Enum<AllowedPathParams>::AsNumber, enumValue, "enum"))

View File

@ -140,7 +140,7 @@ public:
}
ENDPOINT("POST", "body-dto", postBodyDto,
BODY_DTO(TestDto, body)) {
BODY_DTO(Object<TestDto>, body)) {
//OATPP_LOGV(TAG, "POST body %s", body->c_str());
return createDtoResponse(Status::CODE_200, body);
}

View File

@ -25,16 +25,16 @@
#ifndef oatpp_test_web_app_DTOs_hpp
#define oatpp_test_web_app_DTOs_hpp
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace oatpp { namespace test { namespace web { namespace app {
#include OATPP_CODEGEN_BEGIN(DTO)
class TestDto : public oatpp::data::mapping::type::Object {
class TestDto : public oatpp::DTO {
DTO_INIT(TestDto, Object)
DTO_INIT(TestDto, DTO)
DTO_FIELD(String, testValue);
DTO_FIELD(Int32, testValueInt);