Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with_dump only support json, not support dumps #175

Open
nightan42643 opened this issue Jun 15, 2022 · 2 comments
Open

Bug with_dump only support json, not support dumps #175

nightan42643 opened this issue Jun 15, 2022 · 2 comments

Comments

@nightan42643
Copy link

Hey

Does with_dump only support json method but not support dumps method?

@dataclass
class Person(JsonSerializable
                .with_dump(key_transformer=KEY_TRANSFORMER_CAMELCASE)
                .with_load(key_transformer=KEY_TRANSFORMER_SNAKECASE)):
    first_name: str
    last_name: str

arno = Person('Arno','Y')

print(arno.dumps())
print(arno.json)

Result:

{"first_name": "Arno", "last_name": "Y"}
{'firstName': 'Arno', 'lastName': 'Y'}
@ramonhagenaars
Copy link
Owner

Hi @nightan42643,

The .dumps() works, it returns a string. It's just not clear when you only use print, but if you call type, you'll see:

@dataclass
class Person(JsonSerializable
                .with_dump(key_transformer=KEY_TRANSFORMER_CAMELCASE)
                .with_load(key_transformer=KEY_TRANSFORMER_SNAKECASE)):
    first_name: str
    last_name: str

arno = Person('Arno','Y')

print(type(arno.dumps()))
print(type(arno.json))

Result:

<class 'str'>
<class 'dict'>

😉

@nightan42643
Copy link
Author

Hi @nightan42643,

The .dumps() works, it returns a string. It's just not clear when you only use print, but if you call type, you'll see:

@dataclass
class Person(JsonSerializable
                .with_dump(key_transformer=KEY_TRANSFORMER_CAMELCASE)
                .with_load(key_transformer=KEY_TRANSFORMER_SNAKECASE)):
    first_name: str
    last_name: str

arno = Person('Arno','Y')

print(type(arno.dumps()))
print(type(arno.json))

Result:

<class 'str'>
<class 'dict'>

😉

But in this case, the dumps() didn't transfer to the CAMELCASE, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants