CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
json_converter_of_t.h
1#pragma once
2
3#include <system/type_info.h>
4#include <system/scope_guard.h>
5#include <system/object_ext.h>
6#include <system/nullable.h>
7#include <system/exceptions.h>
8#include <system/diagnostics/debug.h>
9#include <system/details/pointer_collection_helpers.h>
10#include <system/details/patterns.h>
11#include <system/default.h>
12#include <cstdint>
13
14#include "system/text/json/reader/utf8_json_reader.h"
15#include "system/text/json/serialization/json_serializer_options.h"
16#include "system/text/json/writer/utf8_json_writer.h"
17#include "system/text/json/throw_helper.h"
18#include "system/text/json/serialization/json_serializer_helpers.h"
19#include "system/text/json/serialization/write_stack.h"
20#include "system/text/json/serialization/json_number_handling.h"
21#include "system/text/json/serialization/read_stack.h"
22#include "system/text/json/json_token_type.h"
23#include "system/text/json/serialization/converter_strategy.h"
24#include "system/text/json/serialization/read_stack_frame.h"
25#include "system/text/json/serialization/write_stack_frame.h"
26#include "system/text/json/serialization/polymorphic_serialization_state.h"
27#include "system/text/json/json_helpers.h"
28#include "system/text/json/reader/json_reader_exception.h"
29#include "system/text/json/json_exception.h"
30#include "system/text/json/serialization/converters/collection/json_dictionary_converter.h"
31#include "system/text/json/serialization/converters/json_metadata_services_converter.h"
32#include "system/text/json/serialization/metadata/json_property_info.h"
33#include "system/text/json/serialization/metadata/json_type_info_of_t.h"
34
35namespace System
36{
37namespace Text
38{
39namespace Json
40{
41namespace Nodes
42{
43template <typename> class JsonValuePrimitive;
44} // namespace Nodes
45namespace Serialization
46{
47namespace Converters
48{
49template <typename, typename> class ArrayConverter;
50template <typename> class CastingConverter;
51template <typename, typename, typename> class DictionaryDefaultConverter;
52template <typename, typename, typename> class DictionaryOfTKeyTValueConverter;
53template <typename> class IDictionaryConverter;
54template <typename> class IEnumerableConverter;
55template <typename, typename> class IEnumerableDefaultConverter;
56template <typename> class IListConverter;
57template <typename> class JsonMetadataServicesConverter;
58class JsonObjectConverter;
59template <typename, typename> class ListOfTConverter;
60template <typename> class NullableConverter;
61template <typename> class StackOrQueueConverter;
62} // namespace Converters
63template <typename, typename> class JsonCollectionConverter;
64template <typename...> class JsonDictionaryConverter;
65} // namespace Serialization
66} // namespace Json
67} // namespace Text
68} // namespace System
69
70namespace System {
71
72namespace Text {
73
74namespace Json {
75
76namespace Serialization {
77
78template<typename T>
79class ASPOSECPP_SHARED_CLASS JsonConverter: public JsonConverterBase
80{
83
84 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
85 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
86
89 template<typename...> friend class JsonDictionaryConverter;
90 template<typename FT0, typename FT1, typename FT2> friend class System::Text::Json::Serialization::Converters::DictionaryDefaultConverter;
91 template<typename FT0, typename FT1, typename FT2> friend class System::Text::Json::Serialization::Converters::DictionaryOfTKeyTValueConverter;
92 template<typename FT0, typename FT1> friend class JsonCollectionConverter;
93 template<typename FT0, typename FT1> friend class System::Text::Json::Serialization::Converters::ArrayConverter;
94 template<typename FT0, typename FT1> friend class System::Text::Json::Serialization::Converters::IEnumerableDefaultConverter;
95 template<typename FT0, typename FT1> friend class System::Text::Json::Serialization::Converters::ListOfTConverter;
96 template<typename FT0> friend class System::Text::Json::Nodes::JsonValuePrimitive;
106
107public:
108
109 virtual bool get_HandleNull()
110 {
111 set_UsesDefaultHandleNull(true);
112 return false;
113 }
114
116 {
117 return pr_Type;
118 }
119
120 bool CanConvert(const System::TypeInfo& typeToConvert) override
121 {
122 return typeToConvert == System::ObjectExt::GetType<T>();
123 }
124
125 virtual T Read(Utf8JsonReader& reader, const System::TypeInfo& typeToConvert, System::SharedPtr<JsonSerializerOptions> options) = 0;
128 {
129 // .NET 5 backward compatibility: hardcode the default converter for primitive key serialization.
130 System::SharedPtr<JsonConverter<T>> fallbackConverter = GetFallbackConverterForPropertyNameSerialization(options);
131 if (System::IsNull(fallbackConverter))
132 {
134 }
135
136 return fallbackConverter->ReadAsPropertyNameCore(System::Ref(reader), typeToConvert, options);
137 }
138
140 {
141 // .NET 5 backward compatibility: hardcode the default converter for primitive key serialization.
142 System::SharedPtr<JsonConverter<T>> fallbackConverter = GetFallbackConverterForPropertyNameSerialization(options);
143 if (System::IsNull(fallbackConverter))
144 {
146 }
147
148 fallbackConverter->WriteAsPropertyNameCore(writer, value, options, false);
149 }
150
151 void SetTemplateWeakPtr(uint32_t argument) override
152 {
153 switch (argument)
154 {
155 case 0:
156 System::Details::CollectionHelpers::SetWeakPointer(0, _fallbackConverterForPropertyNameSerialization);
157 break;
158
159 }
160 }
161
162protected:
163
164 JsonConverter() : pr_Type(System::ObjectExt::GetType<T>())
165 {
166 System::Details::ThisProtector __local_self_ref(this);
167
168 init_IsValueType(System::ObjectExt::GetType<T>().get_IsValueType());
169
170 if (get_HandleNull())
171 {
172 init_HandleNullOnRead(true);
173 init_HandleNullOnWrite(true);
174 }
175 else if (get_UsesDefaultHandleNull())
176 {
177 // If the type doesn't support null, allow the converter a chance to modify.
178 // These semantics are backwards compatible with 3.0.
179 init_HandleNullOnRead(!System::IsNull(System::Default<T>()));
180
181 // The framework handles null automatically on writes.
182 init_HandleNullOnWrite(false);
183 }
184 }
185
187 {
189 }
190
192 {
193 T valueOfT = System::Text::Json::Serialization::Details::UnboxOnWrite<T>(value);
194 Write(writer, valueOfT, options);
195 }
196
198 {
199 T valueOfT = System::Text::Json::Serialization::Details::UnboxOnWrite<T>(value);
200 return OnTryWrite(writer, valueOfT, options, System::Ref(state));
201 }
202
204 {
205 T valueOfT = System::Text::Json::Serialization::Details::UnboxOnWrite<T>(value);
206 WriteAsPropertyName(writer, valueOfT, options);
207 }
208
210 {
211 T valueOfT = System::Text::Json::Serialization::Details::UnboxOnWrite<T>(value);
212 WriteAsPropertyNameCore(writer, valueOfT, options, isWritingExtensionDataProperty);
213 }
214
216 {
217 T valueOfT = System::Text::Json::Serialization::Details::UnboxOnWrite<T>(value);
218 WriteNumberWithCustomHandling(writer, valueOfT, handling);
219 }
220
222 {
223 T valueOfT = System::Text::Json::Serialization::Details::UnboxOnWrite<T>(value);
224 return TryWrite(writer, valueOfT, options, System::Ref(state));
225 }
226
228 {
229 ASPOSE_UNUSED(state);
230 Write(writer, value, options);
231 return true;
232 }
233
234 virtual bool OnTryRead(Utf8JsonReader& reader, const System::TypeInfo& typeToConvert, System::SharedPtr<JsonSerializerOptions> options, ReadStack& state, T& value)
235 {
236 ASPOSE_UNUSED(state);
237 value = Read(System::Ref(reader), typeToConvert, options);
238 return true;
239 }
240
241 bool TryRead(Utf8JsonReader& reader, const System::TypeInfo& typeToConvert, System::SharedPtr<JsonSerializerOptions> options, ReadStack& state, T& value, bool& isPopulatedValue)
242 {
243 if (reader.get_TokenType() == System::Text::Json::JsonTokenType::Null && !get_HandleNullOnRead() && !state.get_IsContinuation())
244 {
245 if (!System::IsNull(System::Default<T>()))
246 {
248 }
249
250 value = System::Default<T>();
251 isPopulatedValue = false;
252 return true;
253 }
254
255 if (get_ConverterStrategy() == System::Text::Json::ConverterStrategy::Value)
256 {
257 // A value converter should never be within a continuation.
258
259 {
260 JsonTokenType originalPropertyTokenType = reader.get_TokenType();
261 int32_t originalPropertyDepth = reader.get_CurrentDepth();
262 int64_t originalPropertyBytesConsumed = reader.get_BytesConsumed();
263
264 if (System::Is(state.Current.NumberHandling, !(_== nullptr)) && get_IsInternalConverterForNumberType())
265 {
266 value = ReadNumberWithCustomHandling(System::Ref(reader), state.Current.NumberHandling.get_Value(), options);
267 }
268 else
269 {
270 value = Read(System::Ref(reader), typeToConvert, options);
271 }
272
273 VerifyRead(originalPropertyTokenType, originalPropertyDepth, originalPropertyBytesConsumed, true, System::Ref(reader));
274 }
275
276 isPopulatedValue = false;
277 return true;
278 }
279
280 bool isContinuation = state.get_IsContinuation();
281 bool success;
282
283 if (!System::ObjectExt::GetType<T>().get_IsValueType() && get_CanBePolymorphic())
284 {
285 // Special case object converters since they don't
286 // require the expensive ReadStack.Push()/Pop() operations.
287
288 success = OnTryRead(System::Ref(reader), typeToConvert, options, System::Ref(state), value);
289
290 isPopulatedValue = false;
291 return success;
292 }
293
296
297 // DEBUG: ensure push/pop operations preserve stack integrity
299
300 state.Push();
301
302 if (!isContinuation)
303 {
304
305 // For performance, only perform token type validation of converters on debug builds.
306
307 state.Current.OriginalTokenType = reader.get_TokenType();
308
309 state.Current.OriginalDepth = reader.get_CurrentDepth();
310 }
311
312 if (!(parentObj == nullptr) && !(propertyInfo == nullptr) && !propertyInfo->get_IsForTypeInfo())
313 {
314 state.Current.HasParentObject = true;
315 }
316
317 success = OnTryRead(System::Ref(reader), typeToConvert, options, System::Ref(state), value);
318
319 if (success)
320 {
321 if (state.get_IsContinuation())
322 {
323 // The resumable converter did not forward to the next converter that previously returned false.
325 }
326
327 VerifyRead(state.Current.OriginalTokenType, state.Current.OriginalDepth, 0, false, System::Ref(reader));
328
329 // No need to clear state.Current.* since a stack pop will occur.
330 }
331
332 isPopulatedValue = state.Current.IsPopulating;
333 state.Pop(success);
334
335 return success;
336 }
337
339 {
340 T typedValue = System::Default<T>();
341 bool success = OnTryRead(System::Ref(reader), typeToConvert, options, System::Ref(state), typedValue);
342 value = System::ExplicitCast<System::Object>(typedValue);
343 return success;
344 }
345
347 {
348 T typedValue = System::Default<T>();
349 bool success = TryRead(System::Ref(reader), typeToConvert, options, System::Ref(state), typedValue, System::Discard<bool>());
350 value = System::ExplicitCast<System::Object>(typedValue);
351 return success;
352 }
353
355 {
356 T typedValue = Read(System::Ref(reader), typeToConvert, options);
357 return System::ExplicitCast<System::Object>(typedValue);
358 }
359
361 {
362 T typedValue = ReadAsPropertyName(System::Ref(reader), typeToConvert, options);
363 return System::ExplicitCast<System::Object>(typedValue);
364 }
365
367 {
368 T typedValue = ReadAsPropertyNameCore(System::Ref(reader), typeToConvert, options);
369 return System::ExplicitCast<System::Object>(typedValue);
370 }
371
373 {
374 T typedValue = ReadNumberWithCustomHandling(System::Ref(reader), handling, options);
375 return System::ExplicitCast<System::Object>(typedValue);
376 }
377
379 {
380 if (writer->get_CurrentDepth() >= options->get_EffectiveMaxDepth())
381 {
383 }
384
385 if (System::IsNull(System::Default<T>()) && !get_HandleNullOnWrite() && IsNull(value))
386 {
387 // We do not pass null values to converters unless HandleNullOnWrite is true. Null values for properties were
388 // already handled in GetMemberAndWriteJson() so we don't need to check for IgnoreNullValues here.
389 writer->WriteNullValue();
390 return true;
391 }
392
393 if (get_ConverterStrategy() == System::Text::Json::ConverterStrategy::Value)
394 {
395
396 int32_t originalPropertyDepth = writer->get_CurrentDepth();
397
398 if (System::Is(state.Current.NumberHandling, !(_== nullptr)) && get_IsInternalConverterForNumberType())
399 {
400 WriteNumberWithCustomHandling(writer, value, state.Current.NumberHandling.get_Value());
401 }
402 else
403 {
404 Write(writer, value, options);
405 }
406
407 VerifyWrite(originalPropertyDepth, writer);
408 return true;
409 }
410
411 bool isContinuation = state.get_IsContinuation();
412 bool success;
413
414 if (!System::ObjectExt::GetType<T>().get_IsValueType() && !System::IsNull(value) && state.Current.PolymorphicSerializationState != System::Text::Json::PolymorphicSerializationState::PolymorphicReEntryStarted)
415 {
417
418 bool canBePolymorphic = get_CanBePolymorphic() || System::Is(jsonTypeInfo->get_PolymorphicTypeResolver(), !(_== nullptr));
419 System::SharedPtr<JsonConverterBase> polymorphicConverter = canBePolymorphic ? ResolvePolymorphicConverter(System::ExplicitCast<System::Object>(value), jsonTypeInfo, options, System::Ref(state)) : nullptr;
420
421 if (!(polymorphicConverter == nullptr))
422 {
423 success = polymorphicConverter->TryWriteAsObject(writer, System::ExplicitCast<System::Object>(value), options, System::Ref(state));
424 state.Current.ExitPolymorphicConverter(success);
425
426 return success;
427 }
428 }
429
430 state.Push();
431
432 success = OnTryWrite(writer, value, options, System::Ref(state));
433 state.Pop(success);
434
435 return success;
436 }
437
439 {
440
441 if (!get_IsInternalConverter())
442 {
443 return TryWrite(writer, value, options, System::Ref(state));
444 }
445
447
448 if (System::IsNull(dictionaryConverter))
449 {
450 // If not JsonDictionaryConverter<T> then we are JsonObject.
451 // Avoid a type reference to JsonObject and its converter to support trimming.
452 // The WriteExtensionDataValue virtual method is overridden by the JsonObject converter.
453
454 WriteExtensionDataValue(writer, value, options);
455
456 return true;
457 }
458
459 if (writer->get_CurrentDepth() >= options->get_EffectiveMaxDepth())
460 {
462 }
463
464 bool isContinuation = state.get_IsContinuation();
465 bool success;
466
467 state.Push();
468
469 if (!isContinuation)
470 {
471
472 state.Current.OriginalDepth = writer->get_CurrentDepth();
473 }
474
475 // Extension data properties change how dictionary key naming policies are applied.
477 state.Current.JsonPropertyInfo = state.Current.JsonTypeInfo->get_ElementTypeInfo()->get_PropertyInfoForTypeInfo();
478
479 success = dictionaryConverter->OnWriteResume(writer, value, options, System::Ref(state));
480 if (success)
481 {
482 VerifyWrite(state.Current.OriginalDepth, writer);
483 }
484
485 state.Pop(success);
486
487 return success;
488 }
489
491 {
492 ASPOSE_UNUSED(writer);
493 ASPOSE_UNUSED(value);
494 ASPOSE_UNUSED(options);
495 CODEPORTING_DEBUG_FAIL1(u"Should not be reachable.");
496
497 throw InvalidOperationException();
498 }
499
500 void VerifyRead(JsonTokenType tokenType, int32_t depth, int64_t bytesConsumed, bool isValueConverter, Utf8JsonReader& reader)
501 {
502
503 switch (tokenType)
504 {
507 {
509 }
510 else if (depth != reader.get_CurrentDepth())
511 {
513 }
514 break;
517 {
519 }
520 else if (depth != reader.get_CurrentDepth())
521 {
523 }
524 break;
526 break;
527 default:
528 if (isValueConverter)
529 {
530 // A value converter should not make any reads.
531 if (reader.get_BytesConsumed() != bytesConsumed)
532 {
534 }
535 }
536 else
537 {
538 // A non-value converter (object or collection) should always have Start and End tokens
539 // unless it is polymorphic, supports null value reads, or handles multiple token types.
540 if (!get_CanBePolymorphic() && !get_SupportsMultipleTokenTypes() && !(get_HandleNullOnRead() && tokenType == System::Text::Json::JsonTokenType::Null))
541 {
543 }
544 }
545 break;
546 }
547 }
548
549 void VerifyWrite(int32_t originalDepth, System::SharedPtr<Utf8JsonWriter> writer)
550 {
551 if (originalDepth != writer->get_CurrentDepth())
552 {
554 }
555 }
556
558 {
559
560 int64_t originalBytesConsumed = reader.get_BytesConsumed();
561 T result = ReadAsPropertyName(System::Ref(reader), typeToConvert, options);
562 if (reader.get_BytesConsumed() != originalBytesConsumed)
563 {
565 }
566
567 return result;
568 }
569
570 virtual void WriteAsPropertyNameCore(System::SharedPtr<Utf8JsonWriter> writer, T value, System::SharedPtr<JsonSerializerOptions> options, bool isWritingExtensionDataProperty)
571 {
572 if (System::IsNull(value))
573 {
574 throw System::ArgumentNullException(u"value");
575 }
576
577 if (isWritingExtensionDataProperty)
578 {
579 // Extension data is meant as mechanism to gather unused JSON properties;
580 // do not apply any custom key conversions and hardcode the default behavior.
581
582 writer->WritePropertyName(System::ObjectExt::ToString(value));
583 return;
584 }
585
586 int32_t originalDepth = writer->get_CurrentDepth();
587 WriteAsPropertyName(writer, value, options);
588 if (originalDepth != writer->get_CurrentDepth() || writer->get_TokenType() != System::Text::Json::JsonTokenType::PropertyName)
589 {
591 }
592 }
593
595 {
596 ASPOSE_UNUSED(reader);
597 ASPOSE_UNUSED(handling);
598 ASPOSE_UNUSED(options);
599 throw InvalidOperationException();
600 }
601
603 {
604 ASPOSE_UNUSED(writer);
605 ASPOSE_UNUSED(value);
606 ASPOSE_UNUSED(handling);
607 throw InvalidOperationException();
608 }
609
611 {
612 try
613 {
614 if (!state.get_IsContinuation() && !get_IsRootLevelMultiContentStreamingConverter())
615 {
616 // This is first call to the converter -- advance the reader
617 // to the first JSON token and perform a read-ahead if necessary.
618 if (!JsonHelpers::TryAdvanceWithOptionalReadAhead(reader, get_RequiresReadAhead()))
619 {
621 if (state.SupportContinuation && System::Is<Object>(state.Current.ReturnValue, result))
622 {
623 // This branch is hit when deserialization has completed in an earlier call
624 // but we're still processing trailing whitespace. Return the result stored in the state machine.
625
626 value = System::ExplicitCast<T>(result);
627 }
628 else
629 {
630 value = System::Default<T>();
631 }
632
633 return reader.get_IsFinalBlock();
634 }
635 }
636
637 bool success = TryRead(System::Ref(reader), state.Current.JsonTypeInfo->get_Type(), options, System::Ref(state), value, System::Discard<bool>());
638 if (success)
639 {
640 if (!reader.get_AllowMultipleValues())
641 {
642 // Read any trailing whitespace. This will throw if JsonCommentHandling=Disallow.
643 // Avoiding setting ReturnValue for the final block; reader.Read() returns 'false' even when this is the final block.
644 if (!reader.Read() && !reader.get_IsFinalBlock())
645 {
646 // This method will re-enter if so set `ReturnValue` which will be returned during re-entry.
647 state.Current.ReturnValue = System::ExplicitCast<System::Object>(value);
648 success = false;
649 }
650 }
651 }
652
653 return success;
654 }
655 catch (Exception& ex)
656 {
657 if (System::ObjectExt::Is<JsonReaderException>(ex))
658 {
659 System::Text::Json::ThrowHelper::ReThrowWithPath(System::Ref(state), System::ExplicitCast<JsonReaderException>(ex));
660 }
661 else if (System::ObjectExt::Is<FormatException>(ex))
662 {
664 }
665 else if (System::ObjectExt::Is<JsonException>(ex))
666 {
667 System::Text::Json::ThrowHelper::AddJsonExceptionInformation(System::Ref(state), reader, System::ExplicitCast<JsonException>(ex));
668 }
669 else if (System::ObjectExt::Is<NotSupportedException>(ex))
670 {
672 }
673
674 throw;
675 }
676 }
677
679 {
680 try
681 {
682 return TryWrite(writer, value, options, System::Ref(state));
683 }
684 catch (Exception& ex)
685 {
687
688 if (System::ObjectExt::Is<JsonException>(ex))
689 {
691 }
692 else if (System::ObjectExt::Is<NotSupportedException>(ex))
693 {
695 }
696
697 throw;
698 }
699 }
700
702 {
703 }
704
705 #ifdef ASPOSE_GET_SHARED_MEMBERS
706 void GetSharedMembers(System::Object::shared_members_type& result) const override
707 {
708 JsonConverterBase::GetSharedMembers(result);
709
710 result.Add("System::Text::Json::Serialization::JsonConverter::pr_Type", this->pr_Type);
711 result.Add("System::Text::Json::Serialization::JsonConverter::_fallbackConverterForPropertyNameSerialization", this->_fallbackConverterForPropertyNameSerialization);
712 }
713 #endif
714
715private:
716
717 System::TypeInfo pr_Type;
718 System::SharedPtr<JsonConverter<T>> _fallbackConverterForPropertyNameSerialization;
719
720 System::Text::Json::ConverterStrategy GetDefaultConverterStrategy() override
721 {
723 }
724
725 static bool IsNull(T value)
726 {
727 return System::IsNull(value);
728 }
729
730 System::SharedPtr<JsonConverter<T>> GetFallbackConverterForPropertyNameSerialization(System::SharedPtr<JsonSerializerOptions> options)
731 {
732 ASPOSE_UNUSED(options);
733 return nullptr;
734 }
735
736};
737
738} // namespace Serialization
739} // namespace Json
740} // namespace Text
741} // namespace System
T get_Value() const
Returns a copy of the value represented by the current object.
Definition: nullable.h:144
Provides static methods that emulate C# Object methods called for non-Object C++ types (strings,...
Definition: object_ext.h:23
static String ToString(const char_t *obj)
Substitution for C# ToString method to work on any C++ type.
Definition: object_ext.h:103
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Definition: json_value_of_t_primitive.h:47
bool HasParentObject
Definition: read_stack_frame.h:75
bool IsPopulating
Definition: read_stack_frame.h:76
Nullable< Serialization::JsonNumberHandling > NumberHandling
Definition: read_stack_frame.h:73
System::SharedPtr< Object > ReturnValue
Definition: read_stack_frame.h:59
int32_t OriginalDepth
Definition: read_stack_frame.h:57
JsonTokenType OriginalTokenType
Definition: read_stack_frame.h:58
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
ReadStackFrame Current
Definition: read_stack.h:44
Definition: dictionary_of_t_key_t_value_converter.h:36
Definition: json_converter_of_t.h:80
bool TryReadAsObject(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state, System::SharedPtr< Object > &value) override
Definition: json_converter_of_t.h:346
void WriteNumberWithCustomHandlingAsObject(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< Object > value, JsonNumberHandling handling) override
Definition: json_converter_of_t.h:215
System::SharedPtr< Object > ReadNumberWithCustomHandlingAsObject(Utf8JsonReader &reader, JsonNumberHandling handling, System::SharedPtr< JsonSerializerOptions > options) override
Definition: json_converter_of_t.h:372
virtual void WriteAsPropertyNameCore(System::SharedPtr< Utf8JsonWriter > writer, T value, System::SharedPtr< JsonSerializerOptions > options, bool isWritingExtensionDataProperty)
Definition: json_converter_of_t.h:570
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: json_converter_of_t.h:151
System::SharedPtr< Object > ReadAsPropertyNameCoreAsObject(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options) override
Definition: json_converter_of_t.h:366
bool WriteCore(System::SharedPtr< Utf8JsonWriter > writer, const T &value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state)
Definition: json_converter_of_t.h:678
bool OnTryWriteAsObject(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< Object > value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state) override
Definition: json_converter_of_t.h:197
virtual T ReadAsPropertyNameCore(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options)
Definition: json_converter_of_t.h:557
void WriteAsPropertyNameAsObject(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< Object > value, System::SharedPtr< JsonSerializerOptions > options) override
Definition: json_converter_of_t.h:203
virtual T Read(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options)=0
virtual void Write(System::SharedPtr< Utf8JsonWriter > writer, T value, System::SharedPtr< JsonSerializerOptions > options)=0
System::TypeInfo get_Type() override
Definition: json_converter_of_t.h:115
void WriteAsObject(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< Object > value, System::SharedPtr< JsonSerializerOptions > options) override
Definition: json_converter_of_t.h:191
virtual T ReadNumberWithCustomHandling(Utf8JsonReader &reader, JsonNumberHandling handling, System::SharedPtr< JsonSerializerOptions > options)
Definition: json_converter_of_t.h:594
bool ReadCore(Utf8JsonReader &reader, T &value, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state)
Definition: json_converter_of_t.h:610
friend class JsonCollectionConverter
Definition: json_converter_of_t.h:92
virtual bool OnTryWrite(System::SharedPtr< Utf8JsonWriter > writer, T value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state)
Definition: json_converter_of_t.h:227
bool CanConvert(const System::TypeInfo &typeToConvert) override
Definition: json_converter_of_t.h:120
virtual void WriteNumberWithCustomHandling(System::SharedPtr< Utf8JsonWriter > writer, T value, JsonNumberHandling handling)
Definition: json_converter_of_t.h:602
bool TryWriteDataExtensionProperty(System::SharedPtr< Utf8JsonWriter > writer, T value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state)
Definition: json_converter_of_t.h:438
bool TryWriteAsObject(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< Object > value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state) override
Definition: json_converter_of_t.h:221
System::SharedPtr< Metadata::JsonTypeInfoBase > CreateJsonTypeInfo(System::SharedPtr< JsonSerializerOptions > options) override
Definition: json_converter_of_t.h:186
System::SharedPtr< Object > ReadAsPropertyNameAsObject(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options) override
Definition: json_converter_of_t.h:360
bool OnTryReadAsObject(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state, System::SharedPtr< Object > &value) override
Definition: json_converter_of_t.h:338
virtual bool OnTryRead(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state, T &value)
Definition: json_converter_of_t.h:234
virtual ~JsonConverter()
Definition: json_converter_of_t.h:701
bool TryWrite(System::SharedPtr< Utf8JsonWriter > writer, const T &value, System::SharedPtr< JsonSerializerOptions > options, WriteStack &state)
Definition: json_converter_of_t.h:378
virtual void WriteExtensionDataValue(System::SharedPtr< Utf8JsonWriter > writer, T value, System::SharedPtr< JsonSerializerOptions > options)
Definition: json_converter_of_t.h:490
virtual T ReadAsPropertyName(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options)
Definition: json_converter_of_t.h:127
void WriteAsPropertyNameCoreAsObject(System::SharedPtr< Utf8JsonWriter > writer, System::SharedPtr< Object > value, System::SharedPtr< JsonSerializerOptions > options, bool isWritingExtensionDataProperty) override
Definition: json_converter_of_t.h:209
void VerifyRead(JsonTokenType tokenType, int32_t depth, int64_t bytesConsumed, bool isValueConverter, Utf8JsonReader &reader)
Definition: json_converter_of_t.h:500
System::SharedPtr< Object > ReadAsObject(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options) override
Definition: json_converter_of_t.h:354
JsonConverter()
Definition: json_converter_of_t.h:164
virtual bool get_HandleNull()
Definition: json_converter_of_t.h:109
bool TryRead(Utf8JsonReader &reader, const System::TypeInfo &typeToConvert, System::SharedPtr< JsonSerializerOptions > options, ReadStack &state, T &value, bool &isPopulatedValue)
Definition: json_converter_of_t.h:241
void VerifyWrite(int32_t originalDepth, System::SharedPtr< Utf8JsonWriter > writer)
Definition: json_converter_of_t.h:549
virtual void WriteAsPropertyName(System::SharedPtr< Utf8JsonWriter > writer, T value, System::SharedPtr< JsonSerializerOptions > options)
Definition: json_converter_of_t.h:139
friend class JsonDictionaryConverter
Definition: json_converter_of_t.h:89
static void ThrowJsonException_DeserializeUnableToConvertValue(const TypeInfo &propertyType)
static void ThrowNotSupportedException(ReadStack &state, Utf8JsonReader &reader, Exception innerException)
static void ReThrowWithPath(ReadStack &state, JsonReaderException ex)
static void AddJsonExceptionInformation(ReadStack &state, Utf8JsonReader &reader, JsonException ex)
static void ThrowJsonException_SerializationConverterWrite(System::SharedPtr< Serialization::JsonConverterBase > converter)
static void ThrowNotSupportedException_DictionaryKeyTypeNotSupported(const TypeInfo &keyType, System::SharedPtr< Serialization::JsonConverterBase > converter)
static void ThrowJsonException_SerializationConverterRead(System::SharedPtr< Serialization::JsonConverterBase > converter)
static void ThrowJsonException_SerializerCycleDetected(int32_t maxDepth)
static void ThrowInvalidOperationException_SerializerCycleDetected(int32_t maxDepth)
Definition: utf8_json_reader.h:78
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
System::Text::Json::PolymorphicSerializationState PolymorphicSerializationState
Definition: write_stack_frame.h:64
bool IsWritingExtensionDataProperty
Definition: write_stack_frame.h:55
int32_t OriginalDepth
Definition: write_stack_frame.h:57
System::SharedPtr< System::Text::Json::Serialization::Metadata::JsonTypeInfoBase > JsonTypeInfo
Definition: write_stack_frame.h:56
void ExitPolymorphicConverter(bool success)
Definition: write_stack.h:34
System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > PeekNestedJsonTypeInfo()
WriteStackFrame Current
Definition: write_stack.h:45
Represents a particular type and provides information about it.
Definition: type_info.h:109
@ Text
Defines color adjustment information for text.
JsonNumberHandling
Definition: json_number_handling.h:16
JsonTokenType
Definition: json_token_type.h:12
ConverterStrategy
Definition: converter_strategy.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
std::enable_if_t< Details::CastType< Source, Result >::Static, Result > AsCast(const Source &value)
Casts the source type to the result type using 'as' operator cast. Used when simple constructor-like ...
Definition: object_ext.h:1219
static auto SafeInvoke(T0 &&expr, T1 &&func)
Implementation of '?.' operator translation.
Definition: object_ext.h:1434