#DTO field mapping from JSON

1 messages · Page 1 of 1 (latest)

hoary cape
#

I have a JSON field in my SQLAlchemy model. This generates a dict response by default in dto_factory. Is it possible to do some field_mapping configuration to specify what/how to expect from the field, and translate that into the API response?

sour dockBOT
#
Notes for DTO field mapping from JSON
At your assistance

@hoary cape

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.

slender mortar
#

What do you type the field as on your model? That’s what the dto would be working off, e.g., json_field: Mapped[dict] = mapped_column(JSON) - dto would to/from a dict.

hoary cape
#

That is it, yeah. Can I just supply more typing information somehow?

#

I.e. could I say it's a dict with these keys inside?

#

To be more specific: if my JSON field is a list of dicts, each with 2 mandatory keys in, could I somehow tell the dto_factory that those keys will exist, and to expose them in the API documentation output?

slender mortar
#

maybe a typed dict? have you tried it?

hoary cape
#

I tried a couple of things, but without success. I had to get this in in time, so I just rewrote as another table with a foreign key.

frozen pebble
#

byte solve