mirror of
https://github.com/oatpp/oatpp.git
synced 2025-04-18 19:00:23 +08:00
Merge branch 'v1.3.0' into better_provider_interface
This commit is contained in:
commit
2d47208df3
@ -4,11 +4,11 @@
|
||||
# https://aka.ms/yaml
|
||||
|
||||
jobs:
|
||||
- job: ubuntu_16_04_mem_pool_on
|
||||
displayName: 'Build - Ubuntu 16.04 - With Memory Pool'
|
||||
- job: ubuntu_20_04_mem_pool_on
|
||||
displayName: 'Build - Ubuntu 20.04 - With Memory Pool'
|
||||
continueOnError: false
|
||||
pool:
|
||||
vmImage: 'Ubuntu 16.04'
|
||||
vmImage: 'ubuntu-20.04'
|
||||
workspace:
|
||||
clean: all
|
||||
steps:
|
||||
@ -25,11 +25,11 @@ jobs:
|
||||
displayName: 'Test'
|
||||
workingDirectory: build
|
||||
|
||||
- job: ubuntu_16_04_mem_pool_off
|
||||
displayName: 'Build - Ubuntu 16.04 - No Memory Pool'
|
||||
- job: ubuntu_20_04_mem_pool_off
|
||||
displayName: 'Build - Ubuntu 20.04 - No Memory Pool'
|
||||
continueOnError: false
|
||||
pool:
|
||||
vmImage: 'Ubuntu 16.04'
|
||||
vmImage: 'ubuntu-20.04'
|
||||
workspace:
|
||||
clean: all
|
||||
steps:
|
||||
|
@ -14,6 +14,7 @@ Contents:
|
||||
- [Response::getBody()](#responsegetbody)
|
||||
- [data::stream::FIFOStream](#datastreamfifostream)
|
||||
- [data::stream::BufferedInputStream](#datastreambufferedinputstream)
|
||||
- [oatpp::parser::json::mapping::Serializer::Config::alwaysIncludeRequired](#oatppparserjsonmappingSerializerConfigalwaysIncludeRequired)
|
||||
|
||||
|
||||
## The New oatpp::String
|
||||
@ -199,7 +200,8 @@ ENDPOINT("GET", "videos/{videoId}", getVideoById,
|
||||
|
||||
## Response::getBody()
|
||||
|
||||
`oatpp::web::protocol::http::outgoing::Response` has a new method `getBody()` to retreive the body of the response. This is handy for response interceptors.
|
||||
`oatpp::web::protocol::http::outgoing::Response` has a new method `getBody()` to retreive the body of the response.
|
||||
This is handy for response interceptors.
|
||||
|
||||
|
||||
## data::stream::FIFOStream
|
||||
@ -223,3 +225,33 @@ You need to implement your own locking.
|
||||
[`BufferedInputStream`](https://oatpp.io/api/latest/oatpp/core/data/stream/Stream/#bufferedinputstream) which unifies
|
||||
the bufferd-stream-interface all existing buffered streams (`InputStreamBufferedProxy`, `BufferInputStream`,
|
||||
`FIFOStream`) to allow for generalisation.
|
||||
|
||||
## oatpp::parser::json::mapping::Serializer::Config::alwaysIncludeRequired
|
||||
|
||||
If `oatpp::parser::json::mapping::Serializer::Config::includeNullFields == false` there might still be the requirement
|
||||
to include some fields even if they are `nullptr`, because they are required by the deserializing end.
|
||||
|
||||
Consider the following DTO and endpoint-snippet.
|
||||
```c++
|
||||
class StatusDto : public oatpp::DTO {
|
||||
DTO_INIT(StatusDto, DTO)
|
||||
DTO_FIELD_INFO(status) {
|
||||
info->required = true;
|
||||
}
|
||||
DTO_FIELD(String, status);
|
||||
DTO_FIELD(Int32, code);
|
||||
DTO_FIELD(String, message);
|
||||
};
|
||||
|
||||
// endpoint code:
|
||||
ENDPOINT("GET", "/status", status) {
|
||||
auto dto = StatusDto::createShared();
|
||||
dto->code = 200;
|
||||
return createDtoResponse(Status::CODE_200, dto);
|
||||
}
|
||||
```
|
||||
With a serializer with its config set to `Serializer::Config::includeNullFields = false`, the snippet would just yield `{"code":200}`.
|
||||
|
||||
However, `status` is a required field.
|
||||
Now, one can set `Serializer::Config::alwaysIncludeRequired = true`.
|
||||
With `alwaysIncludeRequired == true`, the same snippet would yield `{"status":null,"code":200}`, even with `includeNullFields == false`.
|
||||
|
@ -75,6 +75,11 @@ public:
|
||||
*/
|
||||
bool alwaysIncludeRequired = false;
|
||||
|
||||
/**
|
||||
* Always include array or map elements, even if their value is `nullptr`.
|
||||
*/
|
||||
bool alwaysIncludeNullCollectionElements = false;
|
||||
|
||||
/**
|
||||
* If `true` - insert string `"<unknown-type>"` in json field value in case unknown field found.
|
||||
* Fail if `false`.
|
||||
@ -142,7 +147,7 @@ private:
|
||||
bool first = true;
|
||||
|
||||
for(auto& value : *list) {
|
||||
if(value || serializer->getConfig()->includeNullFields) {
|
||||
if(value || serializer->getConfig()->includeNullFields || serializer->getConfig()->alwaysIncludeNullCollectionElements) {
|
||||
(first) ? first = false : stream->writeSimple(",", 1);
|
||||
serializer->serialize(stream, value);
|
||||
}
|
||||
@ -167,7 +172,7 @@ private:
|
||||
|
||||
for(auto& pair : *map) {
|
||||
const auto& value = pair.second;
|
||||
if(value || serializer->m_config->includeNullFields) {
|
||||
if(value || serializer->m_config->includeNullFields || serializer->m_config->alwaysIncludeNullCollectionElements) {
|
||||
(first) ? first = false : stream->writeSimple(",", 1);
|
||||
const auto& key = pair.first;
|
||||
serializeString(stream, key->data(), key->size(), serializer->m_config->escapeFlags);
|
||||
|
Loading…
x
Reference in New Issue
Block a user