[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[rest-practices] JSON style guidelines?



Hi all:

For Candlepin, our primary media type is JSON. We've been using
RESTEasy with Jettison, which does:
JAXB annotated object -> XML -> JSON
As such, we're really representing the XML mappings of our objects in
JSON, rather than the objects themselves. Jettison is doing this with
the BadgerFish mapping convention, so we get JSON like:
{
  "consumer" : {
    "name" : "my consumer",
    "facts" : {
      "entry" : [
        { "key" : "memory", "value" : 12345 },
        { "key" : "memory.free", "value" : 60 }
      ]
    }
  }
}

My feeling is that if you're using JSON, you want it to be as compact as
possible. To that end, I've been working on using Jackson instead, which
cuts out the XML middleman, giving us JSON like:
{
  "name" : "my consumer",
  "facts" : {
    "memory" : 12345,
    "memory.free" : 60
  }
}

The mapping of the "facts" hash is much nicer, but you do lose that
beginning "consumer" type hint. I was thinking we could add a
"type_hint" field inside the returned object instead, or just rely on
the client to know what type to expect based on the url they hit.

What is the opinion of the list? Is anyone aware of any gotchas with the
various JSON styles for autogenerating class representations?

Thanks,

-James

Attachment: pgp5OFeUI0MJT.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]