Defect #6136

JSON API holds less information than XML API

Added by Jay Down over 1 year ago. Updated about 1 year ago.

Status:Closed Start date:2010-08-13
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:REST API
Target version:1.1.0
Affected version:1.0.0-RC Resolution:Fixed

Description

Currently the JSON API provides less information than the XML API. E.g. custom fields (resolution) isn't accessible by the JSON API.

Example:
http://svn.jdownloader.org/issues/1531.json
http://svn.jdownloader.org/issues/1531.xml

(1.0.0.stable.3936)

issue_serialization_patch.diff (7.3 kB) Adam Soltys, 2010-08-15 23:46


Related issues

duplicated by Defect #7158: Issues Custom fields not in json Closed 2010-12-22

Associated revisions

Revision 4458
Added by Jean-Philippe Lang about 1 year ago

Converts IssuesController to use the new API template system and makes xml/json responses consistent (#6136).

History

Updated by Adam Soltys over 1 year ago

This appears to be happening because the issue show action has a custom view (show.builder.xml) that is including the issue's relations, custom fields, etc. whereas the JSON format uses default to_json method on the issue model which doesn't include those things.

I'm going to tackle this by moving the XML builder code into the issue model's to_xml method instead of a view file. Then I'll make the issue's to_json method just call the to_xml method and convert the XML to JSON so we only need to maintain the serialization code in one place.

Updated by Adam Soltys over 1 year ago

I think this patch addresses the issue. The changes are also available at http://github.com/asoltys/redmine/tree/issue_serialization

Updated by Eric Davis over 1 year ago

  • Target version set to Unplanned

This is a real problem with using the XML views. Instead of overriding to_xml, I'm wondering if there is a common method we can make so both XML and JSON formats are always the same. Example:

 1def to_xml
 2  self.to_api_format(:xml)
 3end
 4
 5def to_json
 6  self.to_api_format(:json)
 7end
 8
 9def to_api_format(renderer)
10  {
11    :id => self.id,
12    :subject => self.subject,
13    # ....
14  }
15  # ...
16end

Updated by Jean-Philippe Lang about 1 year ago

  • Status changed from New to Closed
  • Target version changed from Unplanned to 1.1.0
  • Resolution set to Fixed

Fixed in r4458. xml and json responses now use the same template.

Also available in: Atom PDF