ManifestDeserializer.h (2805B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <winget/Manifest.h> 5 #include <cpprest/json.h> 6 #include <winget/JsonUtil.h> 7 8 namespace AppInstaller::Repository::Rest::Schema::V1_0::Json 9 { 10 // Manifest Deserializer. 11 struct ManifestDeserializer 12 { 13 // Gets the manifest from the given json object received from a REST request 14 std::vector<Manifest::Manifest> Deserialize(const web::json::value& responseJsonObject) const; 15 16 // Gets the manifest from the given json Data field 17 std::vector<Manifest::Manifest> DeserializeData(const web::json::value& dataJsonObject) const; 18 19 // Deserializes the AppsAndFeaturesEntries node, returning the set of values below it. 20 virtual std::vector<Manifest::AppsAndFeaturesEntry> DeserializeAppsAndFeaturesEntries(const web::json::array& entries) const; 21 22 // Deserializes the locale; requires that the PackageLocale be set to return an object. 23 virtual std::optional<Manifest::ManifestLocalization> DeserializeLocale(const web::json::value& localeJsonObject) const; 24 25 // Deserializes the locale; requires that the PackageLocale be set to return an object. 26 virtual std::optional<Manifest::InstallationMetadataInfo> DeserializeInstallationMetadata(const web::json::value& installationMetadataJsonObject) const; 27 28 protected: 29 30 template <Manifest::Localization L> 31 inline void TryParseStringLocaleField(Manifest::ManifestLocalization& manifestLocale, const web::json::value& localeJsonObject, std::string_view localeJsonFieldName) const 32 { 33 auto value = AppInstaller::JSON::GetRawStringValueFromJsonNode(localeJsonObject, AppInstaller::JSON::GetUtilityString(localeJsonFieldName)); 34 35 if (AppInstaller::JSON::IsValidNonEmptyStringValue(value)) 36 { 37 manifestLocale.Add<L>(value.value()); 38 } 39 } 40 41 virtual std::optional<Manifest::ManifestInstaller> DeserializeInstaller(const web::json::value& installerJsonObject) const; 42 43 virtual std::map<Manifest::InstallerSwitchType, Manifest::string_t> DeserializeInstallerSwitches(const web::json::value& installerSwitchesJsonObject) const; 44 45 std::optional<Manifest::DependencyList> DeserializeDependency(const web::json::value& dependenciesJsonObject) const; 46 47 virtual Manifest::InstallerTypeEnum ConvertToInstallerType(std::string_view in) const; 48 49 virtual Manifest::UpdateBehaviorEnum ConvertToUpdateBehavior(std::string_view in) const; 50 51 std::vector<Manifest::string_t> ConvertToManifestStringArray(const std::vector<std::string>& values) const; 52 53 virtual Manifest::ManifestVer GetManifestVersion() const; 54 }; 55 }