diff --git a/.travis.yml b/.travis.yml index ffabc442..0c6668ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,17 +3,17 @@ os: - osx - linux -# Ubuntu 14.04 +# Ubuntu 18.04 LTS sudo: required -dist: trusty +dist: bionic -# OS X 10.12 -osx_image: xcode9.2 +# OS X 10.14 +osx_image: xcode11.3 mono: - 4.4.2 -dotnet: 3.0.100 +dotnet: 3.0.101 before_install: - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags diff --git a/README.md b/README.md index 3ddd05f7..c409f818 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ Notation) strings. | Build server | Platform | Build status | |-----------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| | AppVeyor | Windows | [![AppVeyor branch](https://img.shields.io/appveyor/ci/litjson/litjson/develop.svg)](https://ci.appveyor.com/project/litjson/litjson/branch/develop) | -| Bitrise | MacOS | [![Build Status](https://www.bitrise.io/app/5975a00ca2666fb1/status.svg?token=OZnv4YWRw71IVax38Wi50Q&branch=develop)](https://www.bitrise.io/app/5975a00ca2666fb1) | -| Bitrise | Linux | [![Build Status](https://www.bitrise.io/app/4c9ee62c6ba13630/status.svg?token=RBH8UKw-68lQYjageT8VoQ&branch=develop)](https://www.bitrise.io/app/4c9ee62c6ba13630) | +| Bitrise | MacOS | [![Build Status](https://app.bitrise.io/app/5975a00ca2666fb1/status.svg?token=OZnv4YWRw71IVax38Wi50Q&branch=develop)](https://app.bitrise.io/app/5975a00ca2666fb1) | +| Bitrise | Linux | [![Build Status](https://app.bitrise.io/app/4c9ee62c6ba13630/status.svg?token=RBH8UKw-68lQYjageT8VoQ&branch=develop)](https://app.bitrise.io/app/4c9ee62c6ba13630)| | Travis | Linux / MacOS | [![Travis build status](https://travis-ci.org/LitJSON/litjson.svg?branch=develop)](https://travis-ci.org/LitJSON/litjson) | @@ -40,7 +40,7 @@ Code can be compiled using .NET CLI or by launching the bootstrappers in the roo #### Prerequisites The bootstrappers will (locally in repo) - + * Fetch and install .NET Core CLI / SDK version needed to compile LitJSON. * Fetch and install Cake runner * Execute build script with supplied target (`--target=[Target]`) or by default @@ -49,7 +49,7 @@ The bootstrappers will (locally in repo) 1. Build 1. Run unit tests 1. Create NuGet package - + #### Testing This library comes with a set of unit tests using the [NUnit][nunit] diff --git a/build.config b/build.config index b60a6372..71d7b946 100644 --- a/build.config +++ b/build.config @@ -1,3 +1,3 @@ #!/usr/bin/env bash -CAKE_VERSION=0.35.0 -DOTNET_VERSION=3.0.100 +CAKE_VERSION=0.36.0 +DOTNET_VERSION=3.0.101 diff --git a/global.json b/global.json index 052baf7d..c890fe9b 100644 --- a/global.json +++ b/global.json @@ -3,6 +3,6 @@ "src" ], "sdk": { - "version": "3.0.100" + "version": "3.0.101" } } \ No newline at end of file diff --git a/src/LitJson/JsonMapper.cs b/src/LitJson/JsonMapper.cs index 180a33a7..153cc70d 100644 --- a/src/LitJson/JsonMapper.cs +++ b/src/LitJson/JsonMapper.cs @@ -405,6 +405,8 @@ private static object ReadValue (Type inst_type, JsonReader reader) list = new ArrayList (); elem_type = inst_type.GetElementType (); } + + list.Clear(); while (true) { object item = ReadValue (elem_type, reader); diff --git a/src/LitJson/LitJSON.csproj b/src/LitJson/LitJSON.csproj index 6b6b8535..759de5be 100644 --- a/src/LitJson/LitJSON.csproj +++ b/src/LitJson/LitJSON.csproj @@ -11,9 +11,9 @@ - - - + + + diff --git a/test/JsonMapperTest.cs b/test/JsonMapperTest.cs index a980cfa4..63ee5c33 100644 --- a/test/JsonMapperTest.cs +++ b/test/JsonMapperTest.cs @@ -202,6 +202,17 @@ public class NullableEnumTest public NullableEnum? TestEnum; } + class EmptyArrayInJsonDataTest + { + public int[] array; + public string name; + } + + class EmptyArrayInJsonDataTestWrapper + { + public JsonData data = null; + } + [TestFixture] public class JsonMapperTest { @@ -310,13 +321,13 @@ public void ExportEnumsTest () public void ExportEnumDictionaryTest() { Dictionary planets = new Dictionary(); - + planets.Add(Planets.Jupiter, 5); planets.Add(Planets.Saturn, 6); planets.Add(Planets.Uranus, 7); planets.Add(Planets.Neptune, 8); planets.Add(Planets.Pluto, 9); - + string json = JsonMapper.ToJson(planets); Assert.AreEqual("{\"Jupiter\":5,\"Saturn\":6,\"Uranus\":7,\"Neptune\":8,\"Pluto\":9}", json); @@ -417,7 +428,7 @@ public void ExportValueTypesTest () test.TestUInt = 90000000; test.TestULong = 0xFFFFFFFFFFFFFFFF; // = =18446744073709551615 test.TestDateTimeOffset = - new DateTimeOffset(2019, 9, 18, 16, 47, + new DateTimeOffset(2019, 9, 18, 16, 47, 50, 123, TimeSpan.FromHours(8)).AddTicks(4567); string json = JsonMapper.ToJson (test); @@ -871,7 +882,7 @@ public void ImportValueTypesTest () Assert.AreEqual (90000000, test.TestUInt, "A8"); Assert.AreEqual (18446744073709551615L, test.TestULong, "A9"); Assert.AreEqual( - new DateTimeOffset(2019, 9, 18, 16, 47, + new DateTimeOffset(2019, 9, 18, 16, 47, 50, 123, TimeSpan.FromHours(8)).AddTicks(4567), test.TestDateTimeOffset, "A10"); } @@ -1059,5 +1070,34 @@ public void NullableEnumExportTest() expectedJson = "{\"TestEnum\":null}"; Assert.AreEqual(expectedJson, JsonMapper.ToJson(value)); } + + [Test] + public void EmptyArrayInJsonDataExportTest() + { + string testJson = @" + { + ""data"": + { + ""array"": [], + ""name"": ""testName"" + } + }"; + + var response = JsonMapper.ToObject(testJson); + var toJsonResult = response.data.ToJson(); + string expectedJson = "{\"array\":[],\"name\":\"testName\"}"; + Assert.AreEqual(toJsonResult, expectedJson); + } + + [Test] + public void EmptyArrayInJsonDataTest() + { + var toJsonResult = JsonMapper.ToJson(new EmptyArrayInJsonDataTest { + name = "testName", + array = new int[0] + }); + string expectedJson = "{\"array\":[],\"name\":\"testName\"}"; + Assert.AreEqual(toJsonResult, expectedJson); + } } }