public void SerializeObjectWithMultipleGenericLists()
    {
      string containerTypeName = typeof(Container).AssemblyQualifiedName;
      string productTypeName = typeof(Product).AssemblyQualifiedName;

      Container container = new Container
                          {
                            In = new List<Product>(),
                            Out = new List<Product>()
                          };

      string json = JsonConvert.SerializeObject(container, Formatting.Indented,
          new JsonSerializerSettings
              {
                NullValueHandling = NullValueHandling.Ignore,
                TypeNameHandling = TypeNameHandling.All,
                TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
              });

      Assert.AreEqual(@"{
  ""$type"": """ + containerTypeName + @""",
  ""In"": {
    ""$type"": ""System.Collections.Generic.List`1[[" + productTypeName + @"]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"",
    ""$values"": []
  },
  ""Out"": {
    ""$type"": ""System.Collections.Generic.List`1[[" + productTypeName + @"]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"",
    ""$values"": []
  }
}", json);
    }
예제 #2
0
        public void SerializeObjectWithMultipleGenericLists()
        {
            string containerTypeName = typeof(Container).AssemblyQualifiedName;
              string productListTypeName = typeof(List<Product>).AssemblyQualifiedName;

              Container container = new Container
                          {
                            In = new List<Product>(),
                            Out = new List<Product>()
                          };

              string json = JsonConvert.SerializeObject(container, Formatting.Indented,
              new JsonSerializerSettings
              {
                NullValueHandling = NullValueHandling.Ignore,
                TypeNameHandling = TypeNameHandling.All,
                TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
              });

              Assert.AreEqual(@"{
              ""$type"": """ + containerTypeName + @""",
              ""In"": {
            ""$type"": """ + productListTypeName + @""",
            ""$values"": []
              },
              ""Out"": {
            ""$type"": """ + productListTypeName + @""",
            ""$values"": []
              }
            }", json);
        }