internal T Deserialize <T>(string content)
        {
            var js = JsonSerializer.CreateDefault();
            var tr = new StringReader(content);

            return(js.Deserialize <T>(new JsonTextReader(tr)));
        }
        public JsonSerializer()
        {
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            _serializer = NJsonSerializer.CreateDefault(settings);
        }
Esempio n. 3
0
 public ApiResult(HttpStatusCode statusCode, object value)
 {
     StatusCode = (int)statusCode;
     //Data = value == null ? null : System.Text.Json.JsonSerializer.Serialize(value);
     Data = value == null ? null : JToken.FromObject(value, JsonSerializer.CreateDefault(new JsonSerializerSettings
     {
         Converters = { new TypeConverter() }
     }));
 }
        public string Serialize(object obj)
        {
            var js = JsonSerializer.CreateDefault();

            js.DateFormatHandling = DateFormatHandling.IsoDateFormat;
            js.DateFormatString   = "yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz";

            return(js.Serialize(obj));
        }
Esempio n. 5
0
        public void Init()
        {
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
            }.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
            _dateTimeOffset = _offsetDateTime.ToDateTimeOffset();
            _jsonSerializer = JsonSerializer.CreateDefault();

            _resolver = CompositeResolver.Create(new NodaTimeResolver(DateTimeZoneProviders.Tzdb),
                                                 StandardResolver.Default);
        }
Esempio n. 6
0
 private static JsonSerializer _createJsonSerializer(JsonSerializerSettings jsonSerializerSettings)
 {
     return(jsonSerializerSettings == null?JsonSerializer.CreateDefault() : JsonSerializer.Create(jsonSerializerSettings));
 }
Esempio n. 7
0
        /// <summary>
        /// Serializes the specified object to a JSON string using a type, formatting and <see cref="JsonSerializerSettings"/>.
        /// </summary>
        /// <param name="value">The object to serialize.</param>
        /// <param name="settings">The <see cref="JsonSerializerSettings"/> used to serialize the object.
        /// If this is null, default serialization settings will be used.</param>
        /// <param name="type">
        /// The type of the value being serialized.
        /// This parameter is used when <see cref="TypeNameHandling"/> is Auto to write out the type name if the type of the value does not match.
        /// Specifing the type is optional.
        /// </param>
        /// <returns>
        /// A JSON string representation of the object.
        /// </returns>
        public static string SerializeObject(object value, Type type, JsonSerializerSettings settings)
        {
            JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);

            return(SerializeObjectInternal(value, type, jsonSerializer));
        }