Moving json to internal (#1378)

Wrap nlohmann json lib inside core internal api
This commit is contained in:
Victor Vazquez 2021-01-22 11:12:27 -08:00 committed by GitHub
parent c4d89ac5c9
commit 385a7887a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 14764 additions and 10977 deletions

View File

@ -32,7 +32,7 @@ jobs:
Linux_x64_gcc8:
Pool: $(LinuxPool)
OSVmImage:
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CC: '/usr/bin/gcc-8'
CXX: '/usr/bin/g++-8'
@ -40,7 +40,7 @@ jobs:
Linux_x64_gcc9:
Pool: $(LinuxPool)
OSVmImage:
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CC: '/usr/bin/gcc-9'
CXX: '/usr/bin/g++-9'
@ -48,13 +48,13 @@ jobs:
Linux_x64:
Pool: $(LinuxPool)
OSVmImage:
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
BuildArgs: '-j 10'
Win_x86:
Pool: $(WindowsPool)
OSVmImage:
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x86-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: Win32
@ -63,7 +63,7 @@ jobs:
Win_x64:
Pool: $(WindowsPool)
OSVmImage:
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: x64
@ -71,7 +71,7 @@ jobs:
MacOS_x64:
Pool:
OSVmImage: 'macOS-10.14'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-osx'
CHECK_CLANG_FORMAT: 1
@ -79,7 +79,7 @@ jobs:
Linux_x64_with_unit_test:
Pool: $(LinuxPool)
OSVmImage:
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_CODE_COVERAGE=ON'
AptDependencies: 'gcovr lcov'
@ -90,7 +90,7 @@ jobs:
Win_x86_with_unit_test:
Pool: $(WindowsPool)
OSVmImage:
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x86-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: Win32
@ -99,7 +99,7 @@ jobs:
Win_x64_with_unit_test:
Pool: $(WindowsPool)
OSVmImage:
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: x64
@ -108,7 +108,7 @@ jobs:
MacOS_x64_with_unit_test:
Pool:
OSVmImage: 'macOS-10.14'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-osx'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON'
pool:
@ -204,7 +204,7 @@ jobs:
pool:
name: ${{ parameters.WindowsPool }}
variables:
VcpkgDependencies: curl[winssl] libxml2 nlohmann-json
VcpkgDependencies: curl[winssl] libxml2
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
steps:
- template: /eng/common/pipelines/templates/steps/verify-links.yml

View File

@ -25,7 +25,7 @@ jobs:
matrix:
Linux_x64_with_unit_test:
OSVmImage: 'ubuntu-18.04'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-linux'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_CODE_COVERAGE=ON'
AptDependencies: 'gcovr lcov'
@ -35,7 +35,7 @@ jobs:
# Not asking for any transport adapter will default to OS -> windows:winHttp or !windows:libcurl
Win_x86_with_unit_test_winHttp:
OSVmImage: 'windows-2019'
VcpkgInstall: 'libxml2 nlohmann-json'
VcpkgInstall: 'libxml2'
VCPKG_DEFAULT_TRIPLET: 'x86-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: Win32
@ -43,7 +43,7 @@ jobs:
BuildArgs: '-v --parallel 8'
Win_x64_with_unit_test_winHttp:
OSVmImage: 'windows-2019'
VcpkgInstall: 'libxml2 nlohmann-json'
VcpkgInstall: 'libxml2'
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: x64
@ -52,7 +52,7 @@ jobs:
# specify libcurl to be used on Windows
Win_x86_with_unit_test_libcurl:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x86-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: Win32
@ -60,7 +60,7 @@ jobs:
BuildArgs: '-v --parallel 8'
Win_x64_with_unit_test_libcurl:
OSVmImage: 'windows-2019'
VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json'
VcpkgInstall: 'curl[winssl] libxml2'
VCPKG_DEFAULT_TRIPLET: 'x64-windows-static'
CMAKE_GENERATOR: 'Visual Studio 16 2019'
CMAKE_GENERATOR_PLATFORM: x64
@ -68,7 +68,7 @@ jobs:
BuildArgs: '-v --parallel 8'
MacOS_x64_with_unit_test:
OSVmImage: 'macOS-10.14'
VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json'
VcpkgInstall: 'curl[ssl] libxml2 openssl'
VCPKG_DEFAULT_TRIPLET: 'x64-osx'
CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON'
pool:

View File

@ -32,17 +32,6 @@ if(BUILD_TRANSPORT_CURL)
message("Libcurl version ${CURL_VERSION_STRING}")
endif()
# Storage requires 3.6.0 version for using `contains` feature
set(NLOHMANN_JSON_MIN_REQUIRED_VERSION 3.6.0)
# Try to find the config cmake file. Typically for when the integration is made at CMake level
# (CMake project available with a configuration file to consume)
find_package(nlohmann_json ${NLOHMANN_JSON_MIN_REQUIRED_VERSION} CONFIG QUIET)
if(NOT nlohmann_json_FOUND)
# If CMake project/config is not found, last option is to find the library installed. The integration is done by the linker directly.
find_package(nlohmann_json ${NLOHMANN_JSON_MIN_REQUIRED_VERSION} REQUIRED)
endif()
message("nlohmann json version ${nlohmann_json_VERSION}")
if(BUILD_TRANSPORT_CURL)
SET(CURL_TRANSPORT_ADAPTER_SRC src/http/curl/curl.cpp)
SET(CURL_TRANSPORT_ADAPTER_INC inc/azure/core/http/curl/curl.hpp)
@ -62,6 +51,7 @@ set(
inc/azure/core/http/policy.hpp
inc/azure/core/http/transport.hpp
inc/azure/core/internal/contract.hpp
inc/azure/core/internal/json.hpp
inc/azure/core/internal/log.hpp
inc/azure/core/internal/strings.hpp
inc/azure/core/logging/logging.hpp
@ -122,8 +112,7 @@ create_code_coverage(core azure-core azure-core-test)
# ${CURL_INCLUDE_DIRS} needs to be public as long as we #include<curl.h> in public headers.
target_include_directories(azure-core PUBLIC ${CURL_INCLUDE_DIRS})
target_include_directories(azure-core INTERFACE ${nlohmann_json_INCLUDE_DIRS})
target_link_libraries(azure-core INTERFACE Threads::Threads nlohmann_json::nlohmann_json)
target_link_libraries(azure-core INTERFACE Threads::Threads)
if(MSVC)
target_link_libraries(azure-core PRIVATE crypt32)

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/core/internal/json.hpp>
#include <gtest/gtest.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using json = Azure::Core::Internal::Json::json;
// Just a simple test to ensure that Azure Core is bringing nlohmann header
// Just a simple test to ensure that Azure Core internal is wrapping nlohmann json
TEST(Json, create)
{
json j;

View File

@ -3,7 +3,6 @@
#
Source: azure-core-cpp
Version: @AZ_LIBRARY_VERSION@
Build-Depends: nlohmann-json
Description: Microsoft Azure Core SDK for C++
This library provides shared primitives, abstractions, and helpers for modern Azure SDK client libraries written in the C++.
Homepage: https://github.com/Azure/azure-sdk-for-cpp/tree/master/sdk/core/azure-core

View File

@ -5,7 +5,6 @@
include(CMakeFindDependencyMacro)
find_dependency(Threads)
find_dependency(nlohmann_json @NLOHMANN_JSON_MIN_REQUIRED_VERSION@)
if(@BUILD_TRANSPORT_CURL@)
find_dependency(CURL @CURL_MIN_REQUIRED_VERSION@)
endif()

View File

@ -55,6 +55,11 @@ target_include_directories(
target_link_libraries(azure-security-keyvault-common PUBLIC Azure::azure-core)
if(MSVC)
# C28020 and C28204 are introduced by nlohmann/json
target_compile_options(azure-security-keyvault-common PUBLIC /wd28204 /wd28020)
endif()
# coverage. Has no effect if BUILD_CODE_COVERAGE is OFF
create_code_coverage(keyvault azure-security-keyvault-common azure-security-keyvault-common-test)

View File

@ -6,7 +6,7 @@
#include <azure/core/http/policy.hpp>
#include <nlohmann/json.hpp>
#include <azure/core/internal/json.hpp>
#include <type_traits>
using namespace Azure::Security::KeyVault::Common;
@ -43,7 +43,7 @@ KeyVaultException KeyVaultException::CreateFromResponse(
if (contentType.find("json") != std::string::npos)
{
auto jsonParser = nlohmann::json::parse(bodyBuffer);
auto jsonParser = Azure::Core::Internal::Json::json::parse(bodyBuffer);
auto& error = jsonParser["error"];
errorCode = error["code"].get<std::string>();
message = error["message"].get<std::string>();

View File

@ -3,7 +3,7 @@
#include "azure/keyvault/keys/key_vault_key.hpp"
#include <nlohmann/json.hpp>
#include <azure/core/internal/json.hpp>
using namespace Azure::Security::KeyVault::Keys;
@ -24,7 +24,7 @@ KeyVaultKey Details::KeyVaultKeyDeserialize(
Azure::Core::Http::RawResponse const& rawResponse)
{
auto body = rawResponse.GetBody();
auto jsonParser = nlohmann::json::parse(body);
auto jsonParser = Azure::Core::Internal::Json::json::parse(body);
KeyVaultKey key(name);
auto const& jsonKey = jsonParser["key"];

View File

@ -47,7 +47,7 @@ For general suggestions about Azure, use our [Azure feedback forum](https://feed
On Windows, dependencies are managed by [vcpkg](https://github.com/microsoft/vcpkg). You can reference the [Quick Start](https://github.com/microsoft/vcpkg#quick-start-windows) to quickly set yourself up.
After Vcpkg is initialized and bootstrapped, you can install the dependencies:
```BatchFile
vcpkg.exe install libxml2:x64-windows-static curl:x64-windows-static nlohmann-json:x64-windows-static
vcpkg.exe install libxml2:x64-windows-static curl:x64-windows-static
```
#### Unix Platforms
@ -58,7 +58,6 @@ You can use the package manager on different Unix platforms to install the depen
- libxml2.
- OpenSSL.
- libcurl.
- nlohmann-json.
### Build from Source
@ -109,7 +108,6 @@ TODO when ready.
## Dependencies
- [Azure Core SDK](https://github.com/Azure/azure-sdk-for-cpp/blob/master/README.md)
- [nlohmann/json](https://github.com/nlohmann/json)
- libxml2
## Code Samples

View File

@ -6,7 +6,7 @@
#include <type_traits>
#include <azure/core/http/policy.hpp>
#include <nlohmann/json.hpp>
#include <azure/core/internal/json.hpp>
#include "azure/storage/common/constants.hpp"
#include "azure/storage/common/xml_wrapper.hpp"
@ -111,7 +111,7 @@ namespace Azure { namespace Storage {
response->GetHeaders().at(Details::HttpHeaderContentType).find("json")
!= std::string::npos)
{
auto jsonParser = nlohmann::json::parse(bodyBuffer);
auto jsonParser = Azure::Core::Internal::Json::json::parse(bodyBuffer);
errorCode = jsonParser["error"]["code"].get<std::string>();
message = jsonParser["error"]["message"].get<std::string>();
}

View File

@ -12,8 +12,6 @@
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
#include <azure/core/datetime.hpp>
#include <azure/core/http/http.hpp>
#include <azure/core/http/pipeline.hpp>
@ -24,6 +22,8 @@
#include <azure/storage/common/storage_exception.hpp>
#include <azure/storage/files/datalake/dll_import_export.hpp>
#include <azure/core/internal/json.hpp>
namespace Azure { namespace Storage { namespace Files { namespace DataLake {
namespace Details {
@ -548,7 +548,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
Models::ServiceListFileSystemsResult result = bodyBuffer.empty()
? Models::ServiceListFileSystemsResult()
: ServiceListFileSystemsResultFromFileSystemList(
FileSystemListFromJson(nlohmann::json::parse(bodyBuffer)));
FileSystemListFromJson(Azure::Core::Internal::Json::json::parse(bodyBuffer)));
if (response.GetHeaders().find(Details::HeaderContinuationToken)
!= response.GetHeaders().end())
{
@ -564,7 +564,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
}
}
static Models::FileSystem FileSystemFromJson(const nlohmann::json& node)
static Models::FileSystem FileSystemFromJson(const Azure::Core::Internal::Json::json& node)
{
Models::FileSystem result;
result.Name = node["name"].get<std::string>();
@ -574,7 +574,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
return result;
}
static Models::FileSystemList FileSystemListFromJson(const nlohmann::json& node)
static Models::FileSystemList FileSystemListFromJson(
const Azure::Core::Internal::Json::json& node)
{
Models::FileSystemList result;
for (const auto& element : node["filesystems"])
@ -950,7 +951,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
Models::FileSystemListPathsResult result = bodyBuffer.empty()
? Models::FileSystemListPathsResult()
: FileSystemListPathsResultFromPathList(
PathListFromJson(nlohmann::json::parse(bodyBuffer)));
PathListFromJson(Azure::Core::Internal::Json::json::parse(bodyBuffer)));
if (response.GetHeaders().find(Details::HeaderContinuationToken)
!= response.GetHeaders().end())
{
@ -966,7 +967,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
}
}
static Models::Path PathFromJson(const nlohmann::json& node)
static Models::Path PathFromJson(const Azure::Core::Internal::Json::json& node)
{
Models::Path result;
result.Name = node["name"].get<std::string>();
@ -987,7 +988,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
return result;
}
static Models::PathList PathListFromJson(const nlohmann::json& node)
static Models::PathList PathListFromJson(const Azure::Core::Internal::Json::json& node)
{
Models::PathList result;
for (const auto& element : node["paths"])
@ -2057,7 +2058,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
Models::PathSetAccessControlRecursiveResult result = bodyBuffer.empty()
? Models::PathSetAccessControlRecursiveResult()
: PathSetAccessControlRecursiveResultFromSetAccessControlRecursiveResponse(
SetAccessControlRecursiveResponseFromJson(nlohmann::json::parse(bodyBuffer)));
SetAccessControlRecursiveResponseFromJson(
Azure::Core::Internal::Json::json::parse(bodyBuffer)));
if (response.GetHeaders().find(Details::HeaderContinuationToken)
!= response.GetHeaders().end())
{
@ -2073,7 +2075,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
}
}
static Models::AclFailedEntry AclFailedEntryFromJson(const nlohmann::json& node)
static Models::AclFailedEntry AclFailedEntryFromJson(
const Azure::Core::Internal::Json::json& node)
{
Models::AclFailedEntry result;
result.Name = node["name"].get<std::string>();
@ -2083,7 +2086,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
}
static Models::SetAccessControlRecursiveResponse SetAccessControlRecursiveResponseFromJson(
const nlohmann::json& node)
const Azure::Core::Internal::Json::json& node)
{
Models::SetAccessControlRecursiveResponse result;
result.DirectoriesSuccessful = node["directoriesSuccessful"].get<int32_t>();

View File

@ -14,8 +14,6 @@
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
#include <azure/core/datetime.hpp>
#include <azure/core/http/http.hpp>
#include <azure/core/http/pipeline.hpp>
@ -26,6 +24,8 @@
#include <azure/storage/common/storage_exception.hpp>
#include <azure/storage/common/xml_wrapper.hpp>
#include <azure/core/internal/json.hpp>
namespace Azure { namespace Storage { namespace Files { namespace Shares {
namespace Details {
@ -2877,7 +2877,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::string json_body;
{
nlohmann::json json;
Azure::Core::Internal::Json::json json;
SharePermissionToJson(json, createPermissionOptions.Permission);
json_body = json.dump();
}
@ -3461,7 +3461,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
static void SharePermissionToJson(
nlohmann::json& node,
Azure::Core::Internal::Json::json& node,
const Models::SharePermission& object)
{
node["permission"] = object.Permission;
@ -3479,7 +3479,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
Models::ShareGetPermissionResult result = bodyBuffer.empty()
? Models::ShareGetPermissionResult()
: ShareGetPermissionResultFromSharePermission(
SharePermissionFromJson(nlohmann::json::parse(bodyBuffer)));
SharePermissionFromJson(Azure::Core::Internal::Json::json::parse(bodyBuffer)));
return Azure::Core::Response<Models::ShareGetPermissionResult>(
std::move(result), std::move(responsePtr));
}
@ -3490,7 +3490,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
}
static Models::SharePermission SharePermissionFromJson(const nlohmann::json& node)
static Models::SharePermission SharePermissionFromJson(
const Azure::Core::Internal::Json::json& node)
{
Models::SharePermission result;
result.Permission = node["permission"].get<std::string>();