@@ -98,6 +98,7 @@ class StringJsonAttributePerson(base):
9898 # This model uses a String type for "json_tags" to avoid dependency on a nonstandard SQL type in testing, \
9999 # while still demonstrating support
100100 address = Column (MagicJSON )
101+ tags = Column (MagicJSON )
101102
102103 yield StringJsonAttributePerson
103104
@@ -136,7 +137,10 @@ class Computer(base):
136137
137138
138139@pytest .fixture (scope = "module" )
139- def engine (person_tag_model , person_single_tag_model , person_model , computer_model , string_json_attribute_person_model ):
140+ def engine (
141+ person_tag_model , person_single_tag_model , person_model ,
142+ computer_model , string_json_attribute_person_model
143+ ):
140144 engine = create_engine ("sqlite:///:memory:" )
141145 person_tag_model .metadata .create_all (engine )
142146 person_single_tag_model .metadata .create_all (engine )
@@ -245,6 +249,7 @@ class Meta:
245249 name = fields .Str (required = True )
246250 birth_date = fields .DateTime ()
247251 address = fields .Nested (address_schema , many = False )
252+ tags = fields .List (fields .Dict ())
248253
249254 yield StringJsonAttributePersonSchema
250255
@@ -774,6 +779,35 @@ def test_post_list_nested(client, register_routes, computer):
774779 assert response .status_code == 201
775780 assert json .loads (response .get_data ())["data" ]["attributes" ]["tags" ][0 ]["key" ] == "k1"
776781
782+ def test_post_list_nested_field (client , register_routes ):
783+ """
784+ Test a schema contains a nested field is correctly serialized and deserialized
785+ """
786+ payload = {
787+ 'data' : {
788+ 'type' : 'string_json_attribute_person' ,
789+ 'attributes' : {
790+ 'name' : 'test' ,
791+ 'tags' : [
792+ {'key' : 'new_key' , 'value' : 'new_value' }
793+ ],
794+ },
795+ }
796+ }
797+ with client :
798+ response = client .post (
799+ '/string_json_attribute_persons' ,
800+ data = json .dumps (payload ),
801+ content_type = 'application/vnd.api+json'
802+ )
803+ assert response .status_code == 201 , response .json ['errors' ]
804+ assert json .loads (
805+ response .get_data ()
806+ )['data' ]['attributes' ]['tags' ][0 ]['key' ] == 'new_key'
807+ assert json .loads (
808+ response .get_data ()
809+ )['data' ]['attributes' ]['tags' ][0 ]['value' ] == 'new_value'
810+
777811
778812def test_post_list_single (client , register_routes , person ):
779813 payload = {
0 commit comments