Example #1
0
        static JsonMessageSerializer()
        {
            ByteArrayConverter = new ByteArrayConverter();
            ListJsonConverter  = new ListJsonConverter();
            CaseInsensitiveDictionaryJsonConverter = new CaseInsensitiveDictionaryJsonConverter();
            InterfaceProxyConverter  = new InterfaceProxyConverter();
            MessageDataJsonConverter = new MessageDataJsonConverter();
            StringDecimalConverter   = new StringDecimalConverter();

            var namingStrategy = new CamelCaseNamingStrategy();

            DefaultContractResolver deserializerContractResolver = new JsonContractResolver(
                ByteArrayConverter,
                ListJsonConverter,
                CaseInsensitiveDictionaryJsonConverter,
                InterfaceProxyConverter,
                MessageDataJsonConverter,
                StringDecimalConverter)
            {
                NamingStrategy = namingStrategy
            };

            DefaultContractResolver serializerContractResolver =
                new JsonContractResolver(ByteArrayConverter, MessageDataJsonConverter, StringDecimalConverter)
            {
                NamingStrategy = namingStrategy
            };

            _encoding = new Lazy <Encoding>(() => new UTF8Encoding(false, true), LazyThreadSafetyMode.PublicationOnly);

            DeserializerSettings = new JsonSerializerSettings
            {
                NullValueHandling      = NullValueHandling.Ignore,
                DefaultValueHandling   = DefaultValueHandling.Ignore,
                MissingMemberHandling  = MissingMemberHandling.Ignore,
                ObjectCreationHandling = ObjectCreationHandling.Auto,
                ConstructorHandling    = ConstructorHandling.AllowNonPublicDefaultConstructor,
                ContractResolver       = deserializerContractResolver,
                TypeNameHandling       = TypeNameHandling.None,
                DateParseHandling      = DateParseHandling.None,
                DateTimeZoneHandling   = DateTimeZoneHandling.RoundtripKind
            };

            SerializerSettings = new JsonSerializerSettings
            {
                NullValueHandling      = NullValueHandling.Ignore,
                DefaultValueHandling   = DefaultValueHandling.Ignore,
                MissingMemberHandling  = MissingMemberHandling.Ignore,
                ObjectCreationHandling = ObjectCreationHandling.Auto,
                ConstructorHandling    = ConstructorHandling.AllowNonPublicDefaultConstructor,
                ContractResolver       = serializerContractResolver,
                TypeNameHandling       = TypeNameHandling.None,
                DateParseHandling      = DateParseHandling.None,
                DateTimeZoneHandling   = DateTimeZoneHandling.RoundtripKind
            };

            _deserializer = new Lazy <JsonSerializer>(() => JsonSerializer.Create(DeserializerSettings));
            _serializer   = new Lazy <JsonSerializer>(() => JsonSerializer.Create(SerializerSettings));
        }
        static BsonMessageSerializer()
        {
            CaseInsensitiveDictionaryJsonConverter = new CaseInsensitiveDictionaryJsonConverter();
            InterfaceProxyConverter  = new InterfaceProxyConverter();
            InternalTypeConverter    = new InternalTypeConverter();
            MessageDataJsonConverter = new MessageDataJsonConverter();
            IsoDateTimeConverter     = new IsoDateTimeConverter {
                DateTimeStyles = DateTimeStyles.RoundtripKind
            };

            var namingStrategy = new CamelCaseNamingStrategy();

            DefaultContractResolver deserializerContractResolver = new JsonContractResolver(
                CaseInsensitiveDictionaryJsonConverter,
                InternalTypeConverter,
                InterfaceProxyConverter,
                IsoDateTimeConverter,
                MessageDataJsonConverter)
            {
                NamingStrategy = namingStrategy
            };

            IContractResolver serializerContractResolver =
                new JsonContractResolver(IsoDateTimeConverter, MessageDataJsonConverter)
            {
                NamingStrategy = namingStrategy
            };

            DeserializerSettings = new JsonSerializerSettings
            {
                NullValueHandling      = NullValueHandling.Ignore,
                DefaultValueHandling   = DefaultValueHandling.Ignore,
                MissingMemberHandling  = MissingMemberHandling.Ignore,
                ObjectCreationHandling = ObjectCreationHandling.Auto,
                ConstructorHandling    = ConstructorHandling.AllowNonPublicDefaultConstructor,
                ContractResolver       = deserializerContractResolver,
                TypeNameHandling       = TypeNameHandling.None,
                DateParseHandling      = DateParseHandling.None,
                DateTimeZoneHandling   = DateTimeZoneHandling.RoundtripKind
            };

            SerializerSettings = new JsonSerializerSettings
            {
                NullValueHandling      = NullValueHandling.Ignore,
                DefaultValueHandling   = DefaultValueHandling.Ignore,
                MissingMemberHandling  = MissingMemberHandling.Ignore,
                ObjectCreationHandling = ObjectCreationHandling.Auto,
                ConstructorHandling    = ConstructorHandling.AllowNonPublicDefaultConstructor,
                ContractResolver       = serializerContractResolver,
                TypeNameHandling       = TypeNameHandling.None,
                DateParseHandling      = DateParseHandling.None,
                DateTimeZoneHandling   = DateTimeZoneHandling.RoundtripKind
            };

            _deserializer = new Lazy <JsonSerializer>(() => JsonSerializer.Create(DeserializerSettings));
            _serializer   = new Lazy <JsonSerializer>(() => JsonSerializer.Create(SerializerSettings));
        }