mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
Fix associative container on json values (#20606)
This commit is contained in:
parent
1850c07951
commit
de310f6ee1
@ -298,6 +298,17 @@ inline void WriteJsonValue(JsonWriter& Writer, const TMap<FString, T>& Value)
|
|||||||
Writer->WriteObjectEnd();
|
Writer->WriteObjectEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void WriteJsonValue(JsonWriter& Writer, const TSet<T>& Value)
|
||||||
|
{
|
||||||
|
Writer->WriteArrayStart();
|
||||||
|
for (const auto& Element : Value)
|
||||||
|
{
|
||||||
|
WriteJsonValue(Writer, Element);
|
||||||
|
}
|
||||||
|
Writer->WriteArrayEnd();
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, FString& Value)
|
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, FString& Value)
|
||||||
@ -465,6 +476,26 @@ inline bool TryGetJsonValue(const TSharedPtr<FJsonObject>& JsonObject, const FSt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, TSet<T>& ArrayValue)
|
||||||
|
{
|
||||||
|
const TArray<TSharedPtr<FJsonValue>>* JsonArray;
|
||||||
|
if (JsonValue->TryGetArray(JsonArray))
|
||||||
|
{
|
||||||
|
bool ParseSuccess = true;
|
||||||
|
const int32 Count = JsonArray->Num();
|
||||||
|
ArrayValue.Reset();
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
T TmpValue;
|
||||||
|
ParseSuccess &= TryGetJsonValue((*JsonArray)[i], TmpValue);
|
||||||
|
ArrayValue.Emplace(MoveTemp(TmpValue));
|
||||||
|
}
|
||||||
|
return ParseSuccess;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
}
|
}
|
||||||
{{/cppNamespaceDeclarations}}
|
{{/cppNamespaceDeclarations}}
|
||||||
|
@ -307,6 +307,17 @@ inline void WriteJsonValue(JsonWriter& Writer, const TMap<FString, T>& Value)
|
|||||||
Writer->WriteObjectEnd();
|
Writer->WriteObjectEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void WriteJsonValue(JsonWriter& Writer, const TSet<T>& Value)
|
||||||
|
{
|
||||||
|
Writer->WriteArrayStart();
|
||||||
|
for (const auto& Element : Value)
|
||||||
|
{
|
||||||
|
WriteJsonValue(Writer, Element);
|
||||||
|
}
|
||||||
|
Writer->WriteArrayEnd();
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, FString& Value)
|
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, FString& Value)
|
||||||
@ -474,4 +485,24 @@ inline bool TryGetJsonValue(const TSharedPtr<FJsonObject>& JsonObject, const FSt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool TryGetJsonValue(const TSharedPtr<FJsonValue>& JsonValue, TSet<T>& ArrayValue)
|
||||||
|
{
|
||||||
|
const TArray<TSharedPtr<FJsonValue>>* JsonArray;
|
||||||
|
if (JsonValue->TryGetArray(JsonArray))
|
||||||
|
{
|
||||||
|
bool ParseSuccess = true;
|
||||||
|
const int32 Count = JsonArray->Num();
|
||||||
|
ArrayValue.Reset();
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
T TmpValue;
|
||||||
|
ParseSuccess &= TryGetJsonValue((*JsonArray)[i], TmpValue);
|
||||||
|
ArrayValue.Emplace(MoveTemp(TmpValue));
|
||||||
|
}
|
||||||
|
return ParseSuccess;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user