From b61394e80e733011654258c2654e1f57db677aa2 Mon Sep 17 00:00:00 2001 From: Sam Vilain Date: Mon, 7 Apr 2014 14:56:04 -0700 Subject: [PATCH] JSON marshal out should always call 'json_data()' During a recent refactor this function was changed to recurse directly instead of through the helper function. Fix it. --- normalize/record/json.py | 2 +- tests/test_marshal.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/normalize/record/json.py b/normalize/record/json.py index 7485011..e810059 100644 --- a/normalize/record/json.py +++ b/normalize/record/json.py @@ -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 diff --git a/tests/test_marshal.py b/tests/test_marshal.py index 814bc37..9dbd4d1 100644 --- a/tests/test_marshal.py +++ b/tests/test_marshal.py @@ -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, + )