Define JsonType
matusbarabas opened this issue · 5 comments
matusbarabas commented
Can someone help me how to create new JsonType ? My column in databese has json type value.
j2labs commented
dont do that.
call to_primitive(), then call use a function to convert that to json
…On Sun, Nov 11, 2018, 2:44 PM Matúš Barabás ***@***.*** wrote:
Can someone help me how to create new JsonType ? My column in databese has
json type value.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#577>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADBiA4au7GYE3iK0qKv7ogZwICLUY6Dks5uuH4WgaJpZM4YYpda>
.
matusbarabas commented
Can you explain more? What type i should use ? My custom or BaseType? and why i have to call to_primitive function?
j2labs commented
Just use a model.
Consider that Schematics is not far from being a typed dictionary already.
The only thing left for you to do is to call json.dumps
You can have a model with a field that is another model, which how I would
approach your usecase
…On Sun, Nov 11, 2018, 2:51 PM Matúš Barabás ***@***.*** wrote:
Can you explain more? What type i should use ? My custom or BaseType? and
why i have to call to_primitive function?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADBiMYeoWWBen3xRQN0uVQtQOviOO9-ks5uuH--gaJpZM4YYpda>
.
matusbarabas commented
class CreateRequest(Model):
id: IntType = IntType(required=False)
param: StringType = StringType(validators=[json_validator])
This is model, which I used. So, I have to change StringType
to Model
like this?
class CreateRequest(Model):
id: IntType = IntType(required=False)
param: Model
And where to use json dumps
method. It is still not clear for me.
j2labs commented
uhh what?! json as a validator?
the whole point of the to_primitive and to_native functions is to convert
data to and form python native form to a form that is acceptable to
language agnostic encodings, like json
validators are intended to check if the data looks the way the type requires
your code sample appears to conflate these two concepts, tho I cant be sure
i urge you to read the docs and get a good mental model for schematics in
your head. the gist of your second sample is going in the right direction,
but is not yet correct. the docs will get you there.
…On Sun, Nov 11, 2018, 3:07 PM Matúš Barabás ***@***.*** wrote:
class CreateRequest(Model):
id: IntType = IntType(required=False)
param: StringType = StringType(validators=[json_validator])
This is model, which I used. So, I have to change StringType to Model
like this?
class CreateRequest(Model):
id: IntType = IntType(required=False)
param: Model
And where to use json dumps method. It is still not clear for me.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADBiDscXjFRy495pwCYtyvTy52a6Bljks5uuIN-gaJpZM4YYpda>
.