Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Adam Wróbel <https://adamwrobel.com>
Adam Ziolkowski <adam@adsized.com>
Alan Crosswell <alan@columbia.edu>
Alex Seidmann <alex@leanpnt.de>
Anton Shutik <shutikanton@gmail.com>
Ashley Loewen <github@ashleycodes.tech>
Asif Saif Uddin <auvipy@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ any parts of the framework not mentioned in the documentation should generally b
### Added

* Added support for Django 4.1.
* Expanded JSONParser API with `parse_data` method

### Removed

Expand Down
19 changes: 13 additions & 6 deletions rest_framework_json_api/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ def parse_metadata(result):
else:
return {}

def parse(self, stream, media_type=None, parser_context=None):
def parse_data(self, result, parser_context):
"""
Parses the incoming bytestream as JSON and returns the resulting data
Formats the output of calling JSONParser to match the JSON:API specification
and returns the result.
"""
result = super().parse(
stream, media_type=media_type, parser_context=parser_context
)

if not isinstance(result, dict) or "data" not in result:
raise ParseError("Received document does not contain primary data")

Expand Down Expand Up @@ -166,3 +163,13 @@ def parse(self, stream, media_type=None, parser_context=None):
parsed_data.update(self.parse_relationships(data))
parsed_data.update(self.parse_metadata(result))
return parsed_data

def parse(self, stream, media_type=None, parser_context=None):
"""
Parses the incoming bytestream as JSON and returns the resulting data
"""
result = super().parse(
stream, media_type=media_type, parser_context=parser_context
)

return self.parse_data(result, parser_context)