CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
json_serializer_options.h
1#pragma once
2
3#include <system/type_info.h>
4#include <system/exception.h>
5#include <system/object_ext.h>
6#include <system/nullable.h>
7#include <system/details/pointer_collection_helpers.h>
8#include <system/details/patterns.h>
9#include <system/constraints.h>
10#include <system/collections/iequality_comparer.h>
11#include <system/array.h>
12#include <cstdint>
13
14#include "system/text/json/serialization/configuration_list.h"
15#include "system/text/json/serialization/json_converter.h"
16#include "system/text/json/serialization/json_serializer_context.h"
17#include "system/text/json/serialization/json_type_classifier_factory.h"
18#include "system/text/json/serialization/metadata/json_type_info_resolver_chain.h"
19
20namespace System
21{
22namespace Collections
23{
24namespace Concurrent
25{
26template <typename, typename> class ConcurrentDictionary;
27} // namespace Concurrent
28namespace Generic
29{
30template <typename> class IList;
31} // namespace Generic
32} // namespace Collections
33namespace Runtime
34{
35namespace CompilerServices
36{
37template <typename, typename> class ConditionalWeakTable;
38} // namespace CompilerServices
39} // namespace Runtime
40namespace Text
41{
42namespace Encodings
43{
44namespace Web
45{
46class JavaScriptEncoder;
47} // namespace Web
48} // namespace Encodings
49namespace Json
50{
51enum class JsonCommentHandling;
52class JsonDocumentOptions;
53class JsonNamingPolicy;
54class JsonReaderOptions;
55class JsonSerializer;
56enum class JsonSerializerDefaults;
57class JsonWriterOptions;
58namespace Nodes
59{
60class JsonNode;
61class JsonNodeOptions;
62class JsonValueBase;
63template <typename> class JsonValueCustomized;
64} // namespace Nodes
65class ReadStack;
66namespace Serialization
67{
68class JsonConverterBase;
69namespace Converters
70{
71class DefaultObjectConverter;
72class JsonArrayConverter;
73class JsonNodeConverter;
74class JsonObjectConverter;
75class JsonValueConverter;
76class ObjectConverter;
77template <typename> class ObjectDefaultConverter;
78template <typename> class ObjectWithParameterizedConstructorConverter;
79} // namespace Converters
80template <typename> class JsonConverter;
81enum class JsonIgnoreCondition;
82enum class JsonNumberHandling;
83template <typename> class JsonResumableConverter;
84class JsonTypeClassifierContext;
85namespace Metadata
86{
87class IJsonTypeInfoResolver;
88class JsonMetadataServices;
89class JsonPropertyInfoBase;
90class JsonTypeInfoBase;
91class PolymorphicTypeResolver;
92template <typename> class JsonPropertyInfo;
93template <typename> class JsonTypeInfo;
94} // namespace Metadata
95} // namespace Serialization
96class Utf8JsonWriterCache;
97class WriteStack;
98class WriteStackFrame;
99} // namespace Json
100} // namespace Text
101template <typename...> class WeakReference;
102} // namespace System
103
104namespace System {
105
106namespace Text {
107
108namespace Json {
109
110class ASPOSECPP_SHARED_CLASS JsonSerializerOptions final : public System::Object
111{
113 typedef System::Object BaseType;
114
115 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
116 ASPOSECPP_SHARED_RTTI_INFO_DECL();
117
118 friend class JsonSerializer;
119 friend class ReadStack;
135 friend class WriteStack;
136 friend class WriteStackFrame;
137 template<typename FT0> friend class System::Text::Json::Nodes::JsonValueCustomized;
140 template<typename FT0> friend class System::Text::Json::Serialization::JsonConverter;
144
145private:
146
147 class EqualityComparer;
148
149protected:
150
151 class CachingContext final : public System::Object
152 {
153 typedef CachingContext ThisType;
154 typedef System::Object BaseType;
155
156 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
157 RTTI_INFO_DECL();
158
159 private:
160
161 class CacheEntry final : public System::Object
162 {
163 typedef CacheEntry ThisType;
164 typedef System::Object BaseType;
165
166 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
167 RTTI_INFO_DECL();
168
169 public:
170
171 bool HasResult;
173 System::Exception CachedException = nullptr;
174 bool IsNearestAncestorResolved;
176
178 CacheEntry(const System::Exception& exception);
179
181
182 protected:
183
184 #ifdef ASPOSE_GET_SHARED_MEMBERS
185 void GetSharedMembers(System::Object::shared_members_type& result) const override;
186 #endif
187
188 };
189
190 public:
191
193 int32_t get_HashCode();
194 int32_t get_Count();
195
197
198 System::SharedPtr<Serialization::Metadata::JsonTypeInfoBase> GetOrAddTypeInfo(const TypeInfo& type, bool fallBackToNearestAncestorType = false);
200 void Clear();
201
202 protected:
203
205
206 #ifdef ASPOSE_GET_SHARED_MEMBERS
207 void GetSharedMembers(System::Object::shared_members_type& result) const override;
208 #endif
209
210 private:
211
214 int32_t pr_HashCode;
215
220
221 };
222
224 {
226
227 public:
228
230
231 private:
232
233 static const int32_t MaxTrackedContexts = 64;
236
237 static bool TryGetContext(System::SharedPtr<JsonSerializerOptions> options, int32_t hashCode, int32_t& firstUnpopulatedIndex, System::SharedPtr<JsonSerializerOptions::CachingContext>& result);
238
239 static struct __StaticConstructor__ { __StaticConstructor__(); } s_constructor__;
240
241 public:
243 };
244
245private:
246
247 class EqualityComparer final : public Collections::Generic::IEqualityComparer<System::SharedPtr<JsonSerializerOptions>>
248 {
249 typedef EqualityComparer ThisType;
251
252 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
253 RTTI_INFO_DECL();
254
255 public:
256
258 int32_t GetHashCode(System::SharedPtr<JsonSerializerOptions> options) const override;
259
260 };
261
262 class ConverterList final : public Serialization::ConfigurationList<System::SharedPtr<Serialization::JsonConverterBase>>
263 {
264 typedef ConverterList ThisType;
266
267 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
268 RTTI_INFO_DECL();
269
270 public:
271
272 bool get_IsReadOnly() const override;
273
275
276 void SetTemplateWeakPtr(uint32_t argument) override;
277
278 protected:
279
280 void OnCollectionModifying() override;
281
282 virtual ~ConverterList();
283
284 #ifdef ASPOSE_GET_SHARED_MEMBERS
285 void GetSharedMembers(System::Object::shared_members_type& result) const override;
286 #endif
287
288 private:
289
291
292 };
293
294 class TypeClassifierList final : public Serialization::ConfigurationList<System::SharedPtr<Serialization::JsonTypeClassifierFactoryBase>>
295 {
296 typedef TypeClassifierList ThisType;
297 typedef Serialization::ConfigurationList<System::SharedPtr<Serialization::JsonTypeClassifierFactoryBase>> BaseType;
298
299 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
300 RTTI_INFO_DECL();
301
302 public:
303
304 bool get_IsReadOnly() const override;
305
307
308 void SetTemplateWeakPtr(uint32_t argument) override;
309
310 protected:
311
312 void OnCollectionModifying() override;
313
314 virtual ~TypeClassifierList();
315
316 #ifdef ASPOSE_GET_SHARED_MEMBERS
317 void GetSharedMembers(System::Object::shared_members_type& result) const override;
318 #endif
319
320 private:
321
323
324 };
325
326 class OptionsBoundJsonTypeInfoResolverChain final : public Serialization::Metadata::JsonTypeInfoResolverChain
327 {
328 typedef OptionsBoundJsonTypeInfoResolverChain ThisType;
329 typedef Serialization::Metadata::JsonTypeInfoResolverChain BaseType;
330
331 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
332 RTTI_INFO_DECL();
333
334 public:
335
336 bool get_IsReadOnly() const override;
337
338 OptionsBoundJsonTypeInfoResolverChain(System::SharedPtr<JsonSerializerOptions> options);
339
340 void DetachFromOptions();
341
342 protected:
343
344 void ValidateAddedValue(System::SharedPtr<Serialization::Metadata::IJsonTypeInfoResolver> item) override;
345 void OnCollectionModifying() override;
346 void OnCollectionModified() override;
347
348 virtual ~OptionsBoundJsonTypeInfoResolverChain();
349
350 #ifdef ASPOSE_GET_SHARED_MEMBERS
351 void GetSharedMembers(System::Object::shared_members_type& result) const override;
352 #endif
353
354 private:
355
357
358 };
359
360public:
361
367 ASPOSECPP_SHARED_API int32_t get_DefaultBufferSize();
368 ASPOSECPP_SHARED_API void set_DefaultBufferSize(int32_t value);
373 ASPOSECPP_SHARED_API bool get_IgnoreNullValues();
374 ASPOSECPP_SHARED_API void set_IgnoreNullValues(bool value);
379 ASPOSECPP_SHARED_API bool get_IncludeFields();
380 ASPOSECPP_SHARED_API void set_IncludeFields(bool value);
381 ASPOSECPP_SHARED_API int32_t get_MaxDepth();
382 ASPOSECPP_SHARED_API void set_MaxDepth(int32_t value);
385 ASPOSECPP_SHARED_API bool get_PropertyNameCaseInsensitive();
386 ASPOSECPP_SHARED_API void set_PropertyNameCaseInsensitive(bool value);
388 ASPOSECPP_SHARED_API void set_ReadCommentHandling(JsonCommentHandling value);
389 ASPOSECPP_SHARED_API bool get_WriteIndented();
390 ASPOSECPP_SHARED_API void set_WriteIndented(bool value);
391 ASPOSECPP_SHARED_API char16_t get_IndentCharacter();
392 ASPOSECPP_SHARED_API void set_IndentCharacter(char16_t value);
393 ASPOSECPP_SHARED_API int32_t get_IndentSize();
394 ASPOSECPP_SHARED_API void set_IndentSize(int32_t value);
395 ASPOSECPP_SHARED_API String get_NewLine();
396 ASPOSECPP_SHARED_API void set_NewLine(String value);
397 ASPOSECPP_SHARED_API bool get_IsReadOnly();
398
401 template<typename T>
403 {
404 return System::ExplicitCast<System::Text::Json::Serialization::Metadata::JsonTypeInfo<T>>(GetTypeInfoInternal(System::ObjectExt::GetType<T>(), true, true, true));
405 }
406
407 template<typename T>
409 {
410 typeInfo = System::ExplicitCast<System::Text::Json::Serialization::Metadata::JsonTypeInfo<T>>(GetTypeInfoInternal(System::ObjectExt::GetType<T>(), true, nullptr, true));
411 return !System::IsNull(typeInfo);
412 }
413
414 ASPOSECPP_SHARED_API JsonSerializerOptions();
416 ASPOSECPP_SHARED_API JsonSerializerOptions(JsonSerializerDefaults defaults);
417
418 template<typename TContext>
420 {
421 typedef Serialization::JsonSerializerContext BaseT_JsonSerializerContext;
422 assert_is_base_of(BaseT_JsonSerializerContext, TContext);
423 assert_is_constructable(TContext);
424
425 VerifyMutable();
426 TContext context = System::MakeObject<TContext>();
427 context->AssociateWithOptions(System::MakeSharedPtr(this));
428 }
429
430 ASPOSECPP_SHARED_API void MakeReadOnly();
431
432protected:
433
436
437 static const int32_t BufferSizeDefault;
438 static const int32_t DefaultMaxDepth;
439
440 ASPOSECPP_SHARED_API int32_t get_EffectiveMaxDepth();
441 ASPOSECPP_SHARED_API bool get_CanUseFastPathSerializationLogic();
442
443 ASPOSECPP_SHARED_API System::SharedPtr<Serialization::Metadata::JsonTypeInfoBase> GetTypeInfoInternal(const TypeInfo& type, bool ensureConfigured = true, Nullable<bool> ensureNotNull = true, bool resolveIfMutable = false, bool fallBackToNearestAncestorType = false);
445 ASPOSECPP_SHARED_API System::SharedPtr<Serialization::Metadata::JsonTypeInfoBase> GetTypeInfoForRootType(const TypeInfo& type, bool fallBackToNearestAncestorType = false);
447 ASPOSECPP_SHARED_API void ClearCaches();
455 ASPOSECPP_SHARED_API JsonReaderOptions GetReaderOptions();
456 ASPOSECPP_SHARED_API JsonWriterOptions GetWriterOptions();
458 ASPOSECPP_SHARED_API void VerifyMutable();
459
460 ASPOSECPP_SHARED_API virtual ~JsonSerializerOptions();
461
462 #ifdef ASPOSE_GET_SHARED_MEMBERS
463 void GetSharedMembers(System::Object::shared_members_type& result) const override;
464 #endif
465
466private:
467
472 System::SharedPtr<JsonNamingPolicy> _dictionaryKeyPolicy;
473 System::SharedPtr<JsonNamingPolicy> _jsonPropertyNamingPolicy;
474 JsonCommentHandling _readCommentHandling;
478 Serialization::JsonIgnoreCondition _defaultIgnoreCondition;
479 Serialization::JsonNumberHandling _numberHandling;
480 int32_t _defaultBufferSize;
481 int32_t _maxDepth;
482 bool _ignoreNullValues;
483 bool _includeFields;
484 String _newLine;
485 bool _propertyNameCaseInsensitive;
486 bool _writeIndented;
487 char16_t _indentCharacter;
488 int32_t _indentSize;
490 int32_t pr_EffectiveMaxDepth;
491
492 void set_EffectiveMaxDepth(int32_t value);
493
494 Nullable<bool> _canUseFastPathSerializationLogic;
495 bool _isReadOnly;
496 bool _isConfiguredForJsonSerializer;
498
499 String get_DebuggerDisplay();
500
501 static void TrackOptionsInstance(System::SharedPtr<JsonSerializerOptions> options);
503
504};
505
506} // namespace Json
507} // namespace Text
508} // namespace System
Interface providing means to compare two objects for equality. Objects of this class should only be a...
Definition: iequality_comparer.h:18
virtual bool Equals(T x, T y) const =0
Checks if two objects are equal.
Interface of indexed container of elements. Objects of this class should only be allocated using Syst...
Definition: ilist.h:20
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
virtual int32_t GetHashCode() const
Analog of C# Object.GetHashCode() method. Enables hashing of custom objects.
Definition: json_serializer_options.h:37
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:126
Definition: json_document_options.h:26
Definition: json_reader_options.h:26
Definition: json_serializer_options.h:152
System::SharedPtr< JsonSerializerOptions > get_Options()
System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > GetOrAddTypeInfo(const TypeInfo &type, bool fallBackToNearestAncestorType=false)
bool TryGetTypeInfo(const TypeInfo &type, System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > &typeInfo)
CachingContext(System::SharedPtr< JsonSerializerOptions > options, int32_t hashCode)
static System::SharedPtr< JsonSerializerOptions::CachingContext > GetOrCreate(System::SharedPtr< JsonSerializerOptions > options)
Definition: json_serializer_options.h:111
Nodes::JsonNodeOptions GetNodeOptions()
friend class Utf8JsonWriterCache
Definition: json_serializer_options.h:134
System::SharedPtr< Serialization::Metadata::JsonTypeInfo< T > > GetTypeInfo()
Definition: json_serializer_options.h:402
System::SharedPtr< Serialization::JsonConverterBase > GetConverterFromList(const TypeInfo &typeToConvert)
Serialization::JsonNumberHandling get_NumberHandling()
JsonSerializerOptions(JsonSerializerDefaults defaults)
JsonCommentHandling get_ReadCommentHandling()
System::SharedPtr< JsonNamingPolicy > get_DictionaryKeyPolicy()
System::SharedPtr< JsonSerializerOptions::CachingContext > get_CacheContext()
void set_NumberHandling(Serialization::JsonNumberHandling value)
System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > get_ObjectTypeInfo()
System::SharedPtr< Collections::Generic::IList< System::SharedPtr< Serialization::Metadata::IJsonTypeInfoResolver > > > get_TypeInfoResolverChain()
System::SharedPtr< Serialization::JsonTypeClassifierFactoryBase > GetTypeClassifierFromList(System::SharedPtr< Serialization::JsonTypeClassifierContext > context)
static const int32_t BufferSizeDefault
Definition: json_serializer_options.h:437
JsonSerializerOptions(System::SharedPtr< JsonSerializerOptions > options)
System::SharedPtr< Encodings::Web::JavaScriptEncoder > get_Encoder()
void AddContext()
Definition: json_serializer_options.h:419
Serialization::JsonIgnoreCondition get_DefaultIgnoreCondition()
void set_DefaultIgnoreCondition(Serialization::JsonIgnoreCondition value)
System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > GetTypeInfoForRootType(const TypeInfo &type, bool fallBackToNearestAncestorType=false)
friend class JsonSerializer
Definition: json_serializer_options.h:118
bool TryGetTypeInfo(const TypeInfo &type, System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > &typeInfo)
System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > GetTypeInfoInternal(const TypeInfo &type, bool ensureConfigured=true, Nullable< bool > ensureNotNull=true, bool resolveIfMutable=false, bool fallBackToNearestAncestorType=false)
System::SharedPtr< Serialization::JsonConverterBase > GetConverterInternal(const TypeInfo &typeToConvert)
JsonWriterOptions GetWriterOptionsForJsonLines()
void set_DictionaryKeyPolicy(System::SharedPtr< JsonNamingPolicy > value)
void set_PropertyNamingPolicy(System::SharedPtr< JsonNamingPolicy > value)
void set_ReadCommentHandling(JsonCommentHandling value)
static const int32_t DefaultMaxDepth
Definition: json_serializer_options.h:438
bool TryGetPolymorphicTypeInfoForRootType(System::SharedPtr< Object > rootValue, System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > &polymorphicTypeInfo)
System::SharedPtr< Serialization::Metadata::IJsonTypeInfoResolver > get_TypeInfoResolver()
friend class WriteStack
Definition: json_serializer_options.h:135
bool TryGetTypeInfoCached(const TypeInfo &type, System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > &typeInfo)
friend class ReadStack
Definition: json_serializer_options.h:119
void set_Encoder(System::SharedPtr< Encodings::Web::JavaScriptEncoder > value)
bool TryGetTypeInfo(System::SharedPtr< Serialization::Metadata::JsonTypeInfo< T > > &typeInfo)
Definition: json_serializer_options.h:408
System::SharedPtr< Collections::Generic::IList< System::SharedPtr< Serialization::JsonTypeClassifierFactoryBase > > > get_TypeClassifiers()
friend class WriteStackFrame
Definition: json_serializer_options.h:136
System::SharedPtr< Serialization::Metadata::JsonTypeInfoBase > GetTypeInfo(const TypeInfo &type)
static void CheckConverterNullabilityIsSameAsPropertyType(System::SharedPtr< Serialization::JsonConverterBase > converter, const TypeInfo &propertyType)
System::SharedPtr< Serialization::JsonConverterBase > ExpandConverterFactory(System::SharedPtr< Serialization::JsonConverterBase > converter, const TypeInfo &typeToConvert)
void set_TypeInfoResolver(System::SharedPtr< Serialization::Metadata::IJsonTypeInfoResolver > value)
System::SharedPtr< JsonNamingPolicy > get_PropertyNamingPolicy()
System::SharedPtr< Collections::Generic::IList< System::SharedPtr< Serialization::JsonConverterBase > > > get_Converters()
Definition: json_writer_options.h:31
Definition: json_node.h:54
Definition: json_node_options.h:14
Definition: json_value.h:60
Definition: json_value_of_t_customized.h:49
Definition: configuration_list.h:34
bool get_IsReadOnly() const override=0
Checks if collection is read only.
void SetTemplateWeakPtr(uint32_t argument) override
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Definition: configuration_list.h:276
Definition: object_with_parameterized_constructor_converter.h:64
Definition: json_converter_of_t.h:80
Definition: json_resumable_converter_of_t.h:42
Definition: json_serializer_context.h:36
Represents a particular type and provides information about it.
Definition: type_info.h:109
JsonIgnoreCondition
Definition: json_ignore_condition.h:15
JsonNumberHandling
Definition: json_number_handling.h:16
JsonCommentHandling
Definition: json_comment_handling.h:14
JsonSerializerDefaults
Definition: json_serializer_defaults.h:10
Definition: db_command.h:9
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1640
class ASPOSECPP_SHARED_CLASS WeakReference
Represents a weak reference, which references an object while still allowing that object to be delete...
Definition: weak_reference.h:13