On Jul 2, 2012, at 5:08 AM, Andreas Grosam wrote:

> Well, embedding an image encoded in base64 in a JSON document is not that 
> "RESTful" anyway.

Sure it is. Plenty of REST-based APIs do this sort of thing (CouchDB and Atom 
both come to mind.) The REST principles don't dictate any particular transfer 
format for data, and allow for aggregate URLs that represent multiple resources.

> There are  third party JSON libraries which are capable to customize the 
> mapping, though. For instance, it might suffice to implement a method for a 
> Category for NSImage to accomplish this (JPJson library uses this approach 
> for example). That way, you can serialize a hierarchy of Foundation objects 
> which contains a NSImage - no matter where this occurs in the tree.

It's certainly possible to do that, but it doesn't seem like a good idea to me, 
because there's no unambiguous data format associated with an image. Even 
choosing between the two most obvious formats (JPEG and PNG) involves a 
decision about trade-offs between fidelity loss and file size.

I would instead have the app itself decide how to encode the image as data, and 
then set up an unambiguous mapping from NSData to base64-encoded JSON strings. 
(Of course on the other end it's trickier because how does the decoder know 
what strings should be decoded to NSData and which should be left alone? YAML 
has type annotations that provide for this, but JSON doesn't.)

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to