class ObjectMapperTest(unittest.TestCase): def setUp(self): self.object_mapper = ObjectMapper() def test_givenUnregisteredType_whenDeserializing_thenThrowException(self): with self.assertRaises(SerializationException): self.object_mapper.deserialize('{ "name": "foo" }', A_Dto) def test_givenRegisteredType_whenSerializing_thenDeserializeCorrectly( self): dto = self.object_mapper.deserialize('{ "name": "foo" }', A_RegisteredDto) self.assertEqual("foo", dto.name) def test_givenAllowUnregisteredTypes_whenDeserializing_thenIgnoreClassRegistrationStatus( self): self.object_mapper = ObjectMapper(allow_unregistered_types=True) dto = self.object_mapper.deserialize('{ "name": "foo" }', A_Dto) self.assertEqual("foo", dto.name) def test_givenAllowUnregisteredTypes_whenSerializing_thenIgnoreClassRegistrationStatus( self): self.object_mapper = ObjectMapper(allow_unregistered_types=True) dto = A_Dto() dto.name = "foo" json_str = self.object_mapper.serialize(dto) self.assertEqual('{"name": "foo"}', json_str)
def test_givenAllowUnregisteredTypes_whenDeserializing_thenIgnoreClassRegistrationStatus( self): self.object_mapper = ObjectMapper(allow_unregistered_types=True) dto = self.object_mapper.deserialize('{ "name": "foo" }', A_Dto) self.assertEqual("foo", dto.name)
def test_givenAllowUnregisteredTypes_whenSerializing_thenIgnoreClassRegistrationStatus( self): self.object_mapper = ObjectMapper(allow_unregistered_types=True) dto = A_Dto() dto.name = "foo" json_str = self.object_mapper.serialize(dto) self.assertEqual('{"name": "foo"}', json_str)
class ObjectMapperTest(unittest.TestCase): def setUp(self): self.object_mapper = ObjectMapper() def test_givenUnregisteredDtoClass_whenDeserializing_thenIgnoreClassRegistrationStatus( self): dto = self.object_mapper.deserialize('{ "name": "foo" }', A_Dto) self.assertEqual("foo", dto.name) def test_givenUnregisteredDtoClass_whenSerializing_thenIgnoreClassRegistrationStatus( self): dto = A_Dto() dto.name = "foo" json_str = self.object_mapper.serialize(dto) self.assertEqual('{"name": "foo"}', json_str)
from jivago.serialization.object_mapper import ObjectMapper class Dto(object): name: str object_mapper = ObjectMapper() dto: Dto = object_mapper.deserialize('{"name": "paul" }', Dto) json_str = object_mapper.serialize(dto)
def setUp(self): self.object_mapper = ObjectMapper()