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, + )