dataclasses-json
dataclasses-json copied to clipboard
Improved support for mixed casing
When using camelCase letter casing, MyDataClass.from_dict()
still supports the original snake_case letter casing. However, MyDataClass.schema().load()
doesn't. This isn't a big deal - just use from_dict()
. However, from_dict()
doesn't support many=True
. From what I understand, calling from_dict()
repeatedly is slower than once with a list and many=True
.
Is this magic support for mixed casing by from_dict()
intentional? If not, should it be removed? If it is, could it also support many=True
?
I'm running into the same issue. I'm trying to use the marshmallow schema that gets generated by dataclass_json to validate user input and catch a marshmallow ValidationError when the request body doesn't match the schema, but it seems that this method doesn't convert camelCase to snake_case (even though my dataclass was defined with letter_case=LetterCase.CAMEL
)
Hi @djmattyg007, thanks for reporting this
is this magic support for mixed casing by from_dict() intentional?
your suspicion is right that this wasn't intentional, it should be an error to successfully from_dict
on a snake_case field when it expects camelCase
@ewolz3
but it seems that this method doesn't convert camelCase to snake_case (even though my dataclass was defined with letter_case=LetterCase.CAMEL)
this sounds like a different issue -- but perhaps I'm missing something? are you using .schema().load(...)
on a JSON blob with camelCase
?