Ejemplo n.º 1
0
        public IHttpActionResult Get(string id)
        {
            var data = _unitOfWork.Cities.Get(id);
            var json = JilHelper.Serialize(data);

            return(Ok(json));
        }
Ejemplo n.º 2
0
    public void TextWriterReaderTest()
    {
        var       testModel = TestModelFactory.Create();
        TestModel result0;

        using (var fs = new FileStream("TextWriterReaderTest0.json", FileMode.Create))
        {
            var writer = new StreamWriter(fs, Encoding.UTF8);
            writer.WriteJson(testModel);
            writer.Close();
        }

        using (var fs = new FileStream("TextWriterReaderTest0.json", FileMode.Open))
        {
            var reader = new StreamReader(fs, Encoding.UTF8);
            result0 = reader.ReadJson <TestModel>() !;
            reader.Close();
        }

        TestModel result1;

        using (var fs = new FileStream("TextWriterReaderTest1.json", FileMode.Create))
        {
            var writer = new StreamWriter(fs, Encoding.UTF8);
            testModel.Serialize(writer);
            writer.Close();
        }

        using (var fs = new FileStream("TextWriterReaderTest1.json", FileMode.Open))
        {
            var reader = new StreamReader(fs, Encoding.UTF8);
            result1 = reader.ReadJson <TestModel>() !;
            reader.Close();
        }

        Assert.Equal(
            Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime.ToUniversalTime(), testModel.Name,
                         testModel.Gender),
            Tuple.Create(result0.Id, result0.Age, result0.CreateTime, result0.Name, result0.Gender));

        Assert.Equal(
            Tuple.Create(testModel.Id, testModel.Age, testModel.CreateTime.ToUniversalTime(), testModel.Name,
                         testModel.Gender),
            Tuple.Create(result1.Id, result1.Age, result1.CreateTime, result1.Name, result1.Gender));

        using (var fs = new FileStream("TextWriterReaderTest.json", FileMode.Create))
        {
            var writer = new StreamWriter(fs, Encoding.UTF8);
            JilHelper.Serialize <TestModel>(null, writer);
            JilHelper.Serialize(null, writer);
            writer.Close();
        }
    }
Ejemplo n.º 3
0
        public void JilPost()
        {
            var json = JilHelper.Serialize(_dtos, new Options(dateFormat: DateTimeFormat.ISO8601,
                                                              excludeNulls: true, includeInherited: true,
                                                              serializationNameFormat: SerializationNameFormat.CamelCase));

            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "api/Values")
            {
                Content = new StringContent(json, Encoding.UTF8, "application/x-jil")
            };

            httpRequestMessage.Headers.Add("Accept", "application/x-jil");

            var response = _jilHttpClient.SendAsync(httpRequestMessage).Result;

            var result =
                JilHelper.Deserialize <List <TestDto> >(response.Content.ReadAsStringAsync()
                                                        .Result, new Options(dateFormat: DateTimeFormat.ISO8601,
                                                                             excludeNulls: true, includeInherited: true,
                                                                             serializationNameFormat: SerializationNameFormat.CamelCase));
        }
Ejemplo n.º 4
0
 public static string ToJil <T>(this T obj, Options options = null)
 {
     return(JilHelper.Serialize(obj, options));
 }
Ejemplo n.º 5
0
 public static void Serialize(this object?value, TextWriter?output, Options?options = null) =>
 JilHelper.Serialize(value, output, options);
Ejemplo n.º 6
0
 public static string GetExceptionText(string exceptionMessage = null)
 {
     return(JilHelper.Serialize(new GlobalExceptionModel(ResultEnum.Exception, exceptionMessage)));
 }
Ejemplo n.º 7
0
 public static string GetExceptionText(ResultEnum result)
 {
     return(JilHelper.Serialize(new GlobalExceptionModel(ResultEnum.MissingBearerToken)));
 }
Ejemplo n.º 8
0
 public static void WriteJson(this TextWriter?textWriter, object?value, Options?options = null) =>
 JilHelper.Serialize(value, textWriter, options);