Skip to content

Commit

Permalink
JSON marshal out should always call 'json_data()'
Browse files Browse the repository at this point in the history
During a recent refactor this function was changed to recurse directly
instead of through the helper function.  Fix it.
  • Loading branch information
samv committed Apr 7, 2014
1 parent 7652f05 commit b61394e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion normalize/record/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def to_json(record, extraneous=True):
else:
if hasattr(prop, "to_json"):
val = prop.to_json(val)
rv_dict[json_name] = to_json(val, extraneous)
rv_dict[json_name] = _json_data(val, extraneous)

return rv_dict

Expand Down
23 changes: 23 additions & 0 deletions tests/test_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,26 @@ class RegularJsonCheeseRecord(JsonRecord, CheeseRecord):
self.assertNotIn("origin", sanitized)

self.assertJsonDataEqual(rjcr.json_data(extraneous=True), input_json)

class NestedJsonRecord(JsonRecord):
cheese = Property(isa=JsonCheeseRecord)
cheese_list = ListProperty(of=JsonCheeseRecord)

nested_input = dict(
cheese=input_json,
cheese_list=[
{"variety": "Cream Havarti",
"type": "semi-soft",
"color": "pale yellow"},
{"variety": "Adelost",
"type": "semi-soft",
"color": "blue"},
],
)

nested_record = NestedJsonRecord(nested_input)

self.assertJsonDataEqual(
nested_record.json_data(extraneous=True),
nested_input,
)

0 comments on commit b61394e

Please sign in to comment.