Esempio n. 1
0
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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
 def setUp(self):
     self.object_mapper = ObjectMapper()