public void Serializer_serializes_InheritedTypes() { var value = new InheritedTypeBase[] { new InheritedType1 { Base = "Base", Child1 = "Child1" }, new InheritedType2 { Base = "my base", Child2 = "my child 2" } }; var result = JsonConvert.SerializeObject(value, JsonConfiguration.DefaultSerializerSettings); var serializedValue = "[" + Environment.NewLine + " {" + Environment.NewLine + " \"child1\": \"Child1\"," + Environment.NewLine + " \"base\": \"Base\"" + Environment.NewLine + " }," + Environment.NewLine + " {" + Environment.NewLine + " \"child2\": \"my child 2\"," + Environment.NewLine + " \"base\": \"my base\"" + Environment.NewLine + " }" + Environment.NewLine + "]"; Assert.That(result, Is.EqualTo(serializedValue)); }
public static void Serializer_serializes_InheritedTypes() { var value = new InheritedTypeBase[] { new InheritedType1 { Base = "Base", Child1 = "Child1", }, new InheritedType2 { Base = "my base", Child2 = "my child 2", }, }; var result = new ObcJsonSerializer(typeof(InheritedTypeBaseJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).SerializeToString(value); var serializedValue = Invariant($"[\r\n {{\r\n \"child1\": \"Child1\",\r\n \"base\": \"Base\",\r\n \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+InheritedType1, OBeautifulCode.Serialization.Json.Test\"\r\n }},\r\n {{\r\n \"child2\": \"my child 2\",\r\n \"base\": \"my base\",\r\n \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+InheritedType2, OBeautifulCode.Serialization.Json.Test\"\r\n }}\r\n]"); result.Should().Be(serializedValue); }
public static void Serializer_serializes_InheritedTypes() { var value = new InheritedTypeBase[] { new InheritedType1 { Base = "Base", Child1 = "Child1", }, new InheritedType2 { Base = "my base", Child2 = "my child 2", }, }; var result = new NaosJsonSerializer(typeof(GenericDiscoveryJsonConfiguration <InheritedTypeBase>), unregisteredTypeEncounteredStrategy: UnregisteredTypeEncounteredStrategy.Attempt).SerializeToString(value); var serializedValue = "[\r\n {\r\n \"child1\": \"Child1\",\r\n \"base\": \"Base\",\r\n \"$concreteType\": \"Naos.Serialization.Test.JsonConfigurationTest+InheritedType1, Naos.Serialization.Test\"\r\n },\r\n {\r\n \"child2\": \"my child 2\",\r\n \"base\": \"my base\",\r\n \"$concreteType\": \"Naos.Serialization.Test.JsonConfigurationTest+InheritedType2, Naos.Serialization.Test\"\r\n }\r\n]"; result.Should().Be(serializedValue); }