Open spring-projects-issues opened 11 years ago
Peter Grant commented
I needed XML output from Spring Data REST WebMVC for a recent project, and the fastest way to get there seemed to be to convert to Jackson 2 and use the XmlMapper. I didn't add any content negotiation and just made it output XML by default. This satisfied my immediate requirements, so I've attached a patch in case it will help at all. I would be happy to integrate this functionality more cleanly (and less like a proof of concept), but I didn't want to waste time if you had something else in mind. If nothing else, perhaps the conversion to Jackson 2 will prove useful
Jon Brisbin commented
Thanks for the patch. I've actually already upgraded to Jackson 2 in a forked version of the code that I haven't merged into master yet, but will soon.
Output rendering is much easier to customize in the new version of Spring Data REST, so I'll take a look at the latest changes and see if adding XML support is as easy as adding an HttpMessageConverter for it
Jon Brisbin commented
I've pushed some major changes to the codebase into master now. I'm still interested in your use-case w.r.t. XML because that's definitely something we had wanted to tackle at some point. The problem I see right now is that we've put quite a bit of work into figuring out how to handle linked properties. Our idea was to use the Atom namespace's link element to define these but we hadn't yet talked about a good standard XML schema to use for the XML representation of an entity. Ideally it should be as close to the JSON representation as possible since that's using the Spring HATEOAS Resource abstraction. As a general solution, I don't think it's a good idea to diverge too far from that representation unless it's for a particular reason (e.g. JAXB).
XML support is definitely something we want to have a discussion about but I don't think we're quite ready to implement it as a general solution yet. Once the 1.1 release is stabilized, that would be a good time revisit the idea of XML support and see what we need to support it (e.g. HttpMessageConverters
, accepts
/produces
directives on the @RequestMapping
annotations, etc...)
Peter Grant commented
Thank you for the updates. I am happy to wait for fully baked XML support, and I'm much more eager to have the 1.1 changes in a stable release than I am to have XML features, especially since I have a reasonable XML workaround currently using a 1.1 snapshot.
Personally I'm not picky about the schema since my current use case is more or less an ETL process out of non-RESTful web services and into RESTful web services. Whether I map to HAL, RDF, Atom, a custom JAXB-bound schema, or something else, I have plenty of transformation to do regardless. Rather than maintain my own fork of spring-data-rest-webmvc, I changed the date format in the injected ObjectMapper's serialization config and put camel-xmljson in front of the servlet to transform XML requests to JSON and JSON responses to XML. Smooks probably would have worked instead of camel-xmljson but may have been overkill. The performance isn't stellar, but the difference is hardly noticeable compared to the external web service calls and XSLT in my integration.
In a related note, during this project I did find myself wishing I had more control over how individual fields were serialized, though not enough to implement a custom serializer. joda-time may have helped spring-data-rest figure out what it apparently doesn't glean from @TemporalType
annotations on Date fields. If I recall correctly, I also tried using @JsonIgnore
or similar to ignore some fields and tried to get some fields to serialize even though they were marked @Transient
(i.e. calculations), both to no avail. If any such serialization control features are not already in the works, I would be happy to log feature requests and even implement them if it is deemed that they should be included
Jimmy Miller commented
Has there been any movement on this?
Peter Grant opened DATAREST-59 and commented
Attachments:
2 votes, 6 watchers