public CustomJsonSerializer()
        {
            AddValueSerializer <bool>(SerializeBool);
            AddValueSerializer <long>(SerializeLong);
            AddValueSerializer <int>(SerializeInt);
            AddValueSerializer <double>(SerializeDouble);
            AddValueSerializer <float>(SerializeFloat);
            AddValueSerializer <char>(SerializeChar);
            AddValueSerializer <DateTime>(SerializeDateTime);
            AddValueSerializer <PublicId>(SerializePublicId);
            AddValueSerializer <CollectionObject>(SerializeCollection);

            AddPropertyOutputWrapper(ps => ps.Where(p => p.Value != null && (!(p.Value is BaseObject obj) || obj.IsDefined)));
            AddPropertyOutputWrapper(ps => ps.Where(p => !Attribute.IsDefined(p.Property, typeof(JsonIgnoreAttribute))));
            AddPropertyOutputWrapper(ps =>
            {
                var mapped = ps.ToDictionary(k => k.Name, v => v);
                var ret    = new List <CustomProperty>();
                var missingRequiredFields = new List <string>();
                foreach (var p in new string[] { "type", "id" })
                {
                    if (mapped.Remove(p, out var t))
                    {
                        ret.Add(t);
                    }
                    else
                    {
                        missingRequiredFields.Add(p);
                    }
                }
                if (missingRequiredFields.Count > 1)
                {
                    throw new ArgumentNullException(string.Join(", ", missingRequiredFields));
                }
                // else if (missingRequiredFields.Contains("type"))
                // {
                //     throw new ArgumentNullException("type");
                // }
                ret.AddRange(mapped.Values.OrderBy(p => p.Name));
                return(ret);
            });

            var coreConverter = new CoreObjectConverter();

            serializerOptions.Converters.Add(new ObjectCollectionConverter(coreConverter));
            serializerOptions.Converters.Add(new ObjectConverter(coreConverter));
            serializerOptions.Converters.Add(new JsonStringEnumConverter <Visibility>());
            serializerOptions.Converters.Add(new NullableDateTimeConverter());
            serializerOptions.Converters.Add(new DateTimeConverter());
        }
 public ObjectCollectionConverter(CoreObjectConverter coreConverter) : base()
 {
     _coreConverter = coreConverter;
 }