3#include <system/type_info.h>
4#include <system/span.h>
5#include <system/object_ext.h>
6#include <system/nullable.h>
7#include <system/diagnostics/debug.h>
8#include <system/details/pointer_collection_helpers.h>
9#include <system/details/patterns.h>
10#include <system/default.h>
11#include <system/constraints.h>
12#include <system/collections/ienumerator.h>
13#include <system/action.h>
16#include "system/text/json/serialization/converters/object/json_object_converter.h"
17#include "system/text/json/reader/utf8_json_reader.h"
18#include "system/text/json/serialization/json_serializer_options.h"
19#include "system/text/json/serialization/read_stack.h"
20#include "system/text/json/serialization/read_stack_frame.h"
21#include "system/text/json/json_token_type.h"
22#include "system/text/json/throw_helper.h"
23#include "system/text/json/serialization/stack_frame_object_state.h"
24#include "system/text/json/serialization/json_serializer_helpers.h"
25#include "system/text/json/serialization/metadata_property_name.h"
26#include "system/text/json/serialization/polymorphic_serialization_state.h"
27#include "system/text/json/serialization/json_converter.h"
28#include "system/text/json/serialization/stack_frame_property_state.h"
29#include "system/text/json/json_helpers.h"
30#include "system/text/json/writer/utf8_json_writer.h"
31#include "system/text/json/serialization/write_stack.h"
32#include "system/text/json/serialization/write_stack_frame.h"
33#include "system/text/json/serialization/converter_strategy.h"
45class JsonPropertyInfoBase;
68 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
69 RTTI_INFO_TEMPLATE_CLASS(
ThisType, ThisTypeBaseTypesInfo);
87 ASPOSE_UNUSED(typeToConvert);
107 if (jsonTypeInfo->get_HasCreateObject() ==
false)
112 obj = jsonTypeInfo->CreateObjectInstance();
116 value = System::ExplicitCast<T>(obj);
138 value = System::Default<T>();
150 bool success = polymorphicConverter->OnTryReadAsObject(
System::Ref(reader), polymorphicConverter->get_Type(), options,
System::Ref(state), objectResult);
151 value = System::ExplicitCast<T>(objectResult);
169 if (jsonTypeInfo->get_HasCreateObject() ==
false)
174 obj = jsonTypeInfo->CreateObjectInstance();
177 jsonTypeInfo->InvokeOnDeserializing(obj);
197 value = System::Default<T>();
215 jsonTypeInfo->ValidateCanBeUsedForPropertyMetadataSerialization();
216 bool isAlreadyReadMetadataProperty;
218 if (isAlreadyReadMetadataProperty)
225 bool useExtensionProperty;
238 if (!jsonPropertyInfo->get_CanDeserializeOrPopulate())
243 value = System::Default<T>();
254 value = System::Default<T>();
269 value = System::Default<T>();
279 value = System::Default<T>();
289 jsonTypeInfo->InvokeOnDeserialized(obj);
293 value = System::ExplicitCast<T>(obj);
306 jsonTypeInfo->InvokeOnDeserializing(obj);
324 bool isAlreadyReadMetadataProperty;
326 CODEPORTING_DEBUG_ASSERT2(!isAlreadyReadMetadataProperty, u
"Only possible for types that can read metadata, which do not call into the fast-path method.");
328 jsonTypeInfo->ValidateCanBeUsedForPropertyMetadataSerialization();
329 bool useExtensionProperty;
335 jsonTypeInfo->InvokeOnDeserialized(obj);
347 ASPOSE_UNUSED(options);
349 jsonTypeInfo->ValidateCanBeUsedForPropertyMetadataSerialization();
356 jsonTypeInfo->InvokeOnSerializing(obj);
358 writer->WriteStartObject();
366 auto jsonPropertyInfo_enumerator = (jsonTypeInfo->get_PropertyCache()).GetEnumerator();
367 while (jsonPropertyInfo_enumerator.MoveNext())
369 auto&& jsonPropertyInfo = jsonPropertyInfo_enumerator.get_Current();
371 if (jsonPropertyInfo->get_CanSerialize())
377 bool success = jsonPropertyInfo->GetMemberAndWriteJson(obj,
System::Ref(state), writer);
387 if (
System::SafeInvoke(extensionDataProperty, [&](
auto&& expr){
return expr->get_CanSerialize();}) ==
true)
393 bool success = extensionDataProperty->GetMemberAndWriteJsonExtensionData(obj,
System::Ref(state), writer);
397 writer->WriteEndObject();
403 writer->WriteStartObject();
410 jsonTypeInfo->InvokeOnSerializing(obj);
419 if (jsonPropertyInfo->get_CanSerialize())
424 if (!jsonPropertyInfo->GetMemberAndWriteJson(obj,
System::Ref(state), writer))
447 if (
System::SafeInvoke(extensionDataProperty, [&](
auto&& expr){
return expr->get_CanSerialize();}) ==
true)
453 if (!extensionDataProperty->GetMemberAndWriteJsonExtensionData(obj,
System::Ref(state), writer))
475 writer->WriteEndObject();
479 jsonTypeInfo->InvokeOnSerialized(obj);
500 if (!jsonPropertyInfo->get_CanDeserializeOrPopulate())
508 bool success = reader.
TrySkip();
509 CODEPORTING_DEBUG_ASSERT2(success, u
"Serializer should guarantee sufficient read-ahead has been done.");
516 if (!useExtensionProperty)
533 bool requiresReadAhead = jsonPropertyInfo->get_EffectiveConverter()->get_RequiresReadAhead() || state.
Current.
UseExtensionProperty;
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
static bool TryAdvanceWithOptionalReadAhead(Utf8JsonReader &reader, bool requiresReadAhead)
static void ReadWithVerify(Utf8JsonReader &reader)
static void SkipWithVerify(Utf8JsonReader &reader)
System::Text::Json::PolymorphicSerializationState PolymorphicSerializationState
Definition: read_stack_frame.h:65
void InitializePropertiesValidationState(System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > typeInfo)
bool CanContainMetadata
Definition: read_stack_frame.h:62
bool UseExtensionProperty
Definition: read_stack_frame.h:53
System::SharedPtr< Object > ReturnValue
Definition: read_stack_frame.h:59
MetadataPropertyName MetadataPropertyNames
Definition: read_stack_frame.h:64
int32_t OriginalDepth
Definition: read_stack_frame.h:57
System::SharedPtr< System::Text::Json::Serialization::Metadata::PropertyRefCacheBuilder > PropertyRefCacheBuilder
Definition: read_stack_frame.h:71
StackFramePropertyState PropertyState
Definition: read_stack_frame.h:52
StackFrameObjectState ObjectState
Definition: read_stack_frame.h:61
void ValidateAllRequiredPropertiesAreRead(System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > typeInfo)
System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonPropertyInfoBase > JsonPropertyInfo
Definition: read_stack_frame.h:51
System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > JsonTypeInfo
Definition: read_stack_frame.h:60
Definition: read_stack.h:35
bool SupportContinuation
Definition: read_stack.h:50
void ExitPolymorphicConverter(bool success)
ReadStackFrame Current
Definition: read_stack.h:44
System::SharedPtr< Serialization::Metadata::JsonPropertyInfoBase > get_ParentProperty()
TypeInfo PolymorphicResolvedType
Definition: read_stack.h:52
Definition: object_default_converter.h:64
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: object_default_converter.h:484
virtual ~ObjectDefaultConverter()
Definition: object_default_converter.h:537
static void PopulatePropertiesFastPath(System::SharedPtr< Object > obj, System::SharedPtr< Metadata::JsonTypeInfoBase > jsonTypeInfo, System::SharedPtr< JsonSerializerOptions > options, Utf8JsonReader &reader, ReadStack &state)
Definition: object_default_converter.h:304
bool get_CanHaveMetadata() override
Definition: object_default_converter.h:75
static void ReadPropertyValue(System::SharedPtr< Object > obj, ReadStack &state, Utf8JsonReader &reader, System::SharedPtr< Metadata::JsonPropertyInfoBase > jsonPropertyInfo, bool useExtensionProperty)
Definition: object_default_converter.h:497
bool get_SupportsCreateObjectDelegate() override
Definition: object_default_converter.h:80
bool OnTryWrite(System::SharedPtr< Utf8JsonWriter > writer, T value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state) override
Definition: object_default_converter.h:345
static bool ReadAheadPropertyValue(ReadStack &state, Utf8JsonReader &reader, System::SharedPtr< Metadata::JsonPropertyInfoBase > jsonPropertyInfo)
Definition: object_default_converter.h:530
bool OnTryRead(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state, T &value) override
Definition: object_default_converter.h:85
static bool ShouldFlush(WriteStack &state, System::SharedPtr< Utf8JsonWriter > writer)
Definition: json_converter_of_t.h:80
Definition: json_object_converter.h:19
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: json_object_converter.h:35
Definition: json_resumable_converter_of_t.h:42
static void ThrowJsonException_DeserializeUnableToConvertValue(const TypeInfo &propertyType)
static void ThrowNotSupportedException_DeserializeNoConstructor(System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > typeInfo, Utf8JsonReader &reader, ReadStack &state)
Definition: utf8_json_reader.h:78
JsonTokenType get_TokenType()
bool TrySkipPartial(int32_t targetDepth)
bool ProcessedStartToken
Definition: write_stack_frame.h:58
Nullable< Serialization::JsonNumberHandling > NumberHandling
Definition: write_stack_frame.h:66
System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonPropertyInfoBase > JsonPropertyInfo
Definition: write_stack_frame.h:54
int32_t EnumeratorIndex
Definition: write_stack_frame.h:61
bool ProcessedEndToken
Definition: write_stack_frame.h:59
System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > JsonTypeInfo
Definition: write_stack_frame.h:56
Definition: write_stack.h:34
bool SupportContinuation
Definition: write_stack.h:54
WriteStackFrame Current
Definition: write_stack.h:45
bool get_CurrentContainsMetadata()
Represents a particular type and provides information about it.
Definition: type_info.h:109
@ Text
Defines color adjustment information for text.
void ValidateMetadataForObjectConverter(ReadStack &state)
ReadOnlySpan< uint8_t > GetPropertyName(ReadStack &state, Utf8JsonReader &reader, System::SharedPtr< JsonSerializerOptions > options, bool &isAlreadyReadMetadataProperty)
MetadataPropertyName WriteMetadataForObject(System::SharedPtr< JsonConverterBase > jsonConverter, WriteStack &state, System::SharedPtr< Utf8JsonWriter > writer)
System::SharedPtr< Metadata::JsonPropertyInfoBase > LookupProperty(System::SharedPtr< Object > obj, ReadOnlySpan< uint8_t > unescapedPropertyName, ReadStack &state, System::SharedPtr< JsonSerializerOptions > options, bool &useExtensionProperty, bool createExtensionProperty=true)
bool TryReadMetadata(System::SharedPtr< JsonConverterBase > converter, System::SharedPtr< Metadata::JsonTypeInfoBase > jsonTypeInfo, Utf8JsonReader &reader, ReadStack &state)
JsonTokenType
Definition: json_token_type.h:12
@ PolymorphicReEntryStarted
MetadataPropertyName
Definition: metadata_property_name.h:13
Definition: db_command.h:9
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1640
decltype(Ref(std::declval< T & >())) Ref(const std::reference_wrapper< T > &wrapper)
Wrapper to make sure Ref(std::ref(DynamicWeakPtr)) works.
Definition: dynamic_weak_ptr.h:207
static auto SafeInvoke(T0 &&expr, T1 &&func)
Implementation of '?.' operator translation.
Definition: object_ext.h:1434