object-mapper icon indicating copy to clipboard operation
object-mapper copied to clipboard

dataclass are not supported

Open arkadyzalko opened this issue 4 years ago • 3 comments

@dataclass is a pretty good feature and unfortunatelly is not supported.

https://github.com/marazt/object-mapper/blob/9d62e9bf00cd78afdaccd6e950a6bb4a1dd1cc06/mapper/object_mapper.py#L171

Example

class ObjectMapperTest(unittest.TestCase):
    """
    Unit tests for the `ObjectMapper` module.
    """
    @dataclass
    class FromTestDataClass:
        a: int
        b: str

    @dataclass
    class ToTestDataClass:
        a: int
        b: str

    def test_mapping_creation_without_mappings_correct_using_dataclass(self):
        """ Test mapping creation without mappings with dataclass"""

        # Arrange
        from_class = FromTestClass()
        mapper = ObjectMapper()
        mapper.create_map(FromTestDataClass, ToTestDataClass)

        # Act
        result = mapper.map(FromTestDataClass(a=1, b='2'))

        # Assert
        self.assertTrue(isinstance(result, ToTestDataClass), "Target types must be same")
        self.assertEqual(result.name, from_class.name, "Name mapping must be equal")
        self.assertEqual(result, ToTestDataClass(a=1, b='2'), "Class instance must be equal")

arkadyzalko avatar Oct 16 '20 06:10 arkadyzalko

There is a pull request for this: #26

raman-nbg avatar Dec 23 '20 14:12 raman-nbg

Nice addition, when would we publish it?

arisliang avatar Dec 29 '20 08:12 arisliang

The PR is not merged yet. @marazt could you merge this PR?

arkadyzalko avatar Apr 20 '21 03:04 arkadyzalko