dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

Feature Request: Include data validation for dataclass json

Open taidinh-tiki opened this issue 4 years ago • 3 comments

taidinh-tiki avatar May 29 '20 06:05 taidinh-tiki

Can you provide more details what you need? Are you aware of DataClassJson.schema().loads()?

RunOrVeith avatar May 29 '20 08:05 RunOrVeith

Can you provide more details what you need? Are you aware of DataClassJson.schema().loads()?

Ah okay, let me check it, but please don't close the issue, I may investigate it more and want to customize the validation logic. E.g field A must present if field B present or something like that, thanks for your swift reply <#

taidinh-tiki avatar May 29 '20 09:05 taidinh-tiki

Can you provide more details what you need? Are you aware of DataClassJson.schema().loads()?

This doesn't work if I want to work with camelCase JSON. Even though I define my dataclass with @dataclass_json(letter_case=LetterCase.CAMEL), the schema the gets generated by .schema() is still looking for snake_case.

I am expecting to be able to do something like:

from marshmallow import ValidationError

try:
    mydataclass.schema().load(request.json)  # request.json will be camelCase
except ValidationError as err:
   # do something with marshmallow's err.normalized_messages()

ewolz3 avatar Apr 13 '21 16:04 ewolz3

Closing as stale - feel free to reopen and ping you think we should do something about this.

george-zubrienko avatar Jul 02 '23 17:07 george-zubrienko