Exemple #1
0
        public void Can_force_specific_TypeInfo()
        {
            JsConfig<Dog>.IncludeTypeInfo = true;
            var pets = new ExplicitPets()
            {
                Cat = new Cat { Name = "Cat" },
                Dog = new Dog { Name = "Dog" },
            };

            Assert.That(pets.ToJson(), Is.EqualTo(
                @"{""Cat"":{""Name"":""Cat""},""Dog"":{""__type"":""ServiceStack.Text.Tests.JsonTests.Dog, ServiceStack.Text.Tests"",""Name"":""Dog""}}"));

            Assert.That(new Dog { Name = "Dog" }.ToJson(), Is.EqualTo(
                @"{""__type"":""ServiceStack.Text.Tests.JsonTests.Dog, ServiceStack.Text.Tests"",""Name"":""Dog""}"));
        }
Exemple #2
0
        public void Can_force_specific_TypeInfo()
        {
            //This configuration has to be set before first usage of WriteType<OtherDog>, otherwise this setting change will not be applied
            JsConfig <OtherDog> .IncludeTypeInfo = true;

            var pets = new ExplicitPets()
            {
                Cat = new Cat {
                    Name = "Cat"
                },
                Dog = new OtherDog {
                    Name = "Dog"
                },
            };

            Assert.That(pets.ToJson(), Is.EqualTo(
                            @"{""Cat"":{""Name"":""Cat""},""Dog"":{""__type"":""ServiceStack.Text.Tests.JsonTests.PolymorphicListTests+OtherDog, " + assemblyName + @""",""Name"":""Dog""}}"));

            Assert.That(new OtherDog {
                Name = "Dog"
            }.ToJson(), Is.EqualTo(
                            @"{""__type"":""ServiceStack.Text.Tests.JsonTests.PolymorphicListTests+OtherDog, " + assemblyName + @""",""Name"":""Dog""}"));
        }
		public void Can_force_specific_TypeInfo()
		{
			JsConfig<Dog>.IncludeTypeInfo = true;
			var pets = new ExplicitPets()
			{
				Cat = new Cat { Name = "Cat" },
				Dog = new Dog { Name = "Dog" },
			};

			Assert.That(pets.ToJson(), Is.EqualTo(
				@"{""Cat"":{""Name"":""Cat""},""Dog"":{""__type"":""ServiceStack.Text.Tests.JsonTests.Dog, ServiceStack.Text.Tests"",""Name"":""Dog""}}"));

			Assert.That(new Dog { Name = "Dog" }.ToJson(), Is.EqualTo(
				@"{""__type"":""ServiceStack.Text.Tests.JsonTests.Dog, ServiceStack.Text.Tests"",""Name"":""Dog""}"));
		}
		public void Can_force_specific_TypeInfo()
		{
			//This configuration has to be set before first usage of WriteType<OtherDog>, otherwise this setting change will not be applied
			JsConfig<OtherDog>.IncludeTypeInfo = true;

			var pets = new ExplicitPets()
			{
				Cat = new Cat { Name = "Cat" },
				Dog = new OtherDog { Name = "Dog" },
			};
			Assert.That(pets.ToJson(), Is.EqualTo(
				@"{""Cat"":{""Name"":""Cat""},""Dog"":{""__type"":""ServiceStack.Text.Tests.JsonTests.PolymorphicListTests+OtherDog, " + assemblyName + @""",""Name"":""Dog""}}"));

			Assert.That(new OtherDog { Name = "Dog" }.ToJson(), Is.EqualTo(
				@"{""__type"":""ServiceStack.Text.Tests.JsonTests.PolymorphicListTests+OtherDog, " + assemblyName + @""",""Name"":""Dog""}"));
		}