-1

I'm using Spring-Boot + Jackson to implement a Rest API. When I return some object from my methods the controllers are building a JSON compliant response. However, that's not happening when I return primitive wrappers as String or Long (they don't act as property-value maps, they're just value wrappers in Java). Is it a non-desirable practice to return a non JSON compliant response from the API?

enter image description here

enter image description here

1
  • 3
    Is it a non-desirable practice to return a non JSON compliant response [from a JSON API]? -- Why would you ever want to? Feb 25, 2016 at 16:06

1 Answer 1

5

A JSON API should return JSON. That's why it's called a JSON API. All the users of the API will be expecting JSON, because it's a JSON API.

If a JSON API returns something other than JSON, then it is not a JSON API.

If you're going to continue to call your JSON API a JSON API, and it returns something other than JSON, then indeed that is quite undesirable.

2
  • Well, I'm not defining it strictly as a JSON API. I'm just designing a modern API and I was bothering if most of the third party clients do expect JSON as a response. Making it a JSON result requires some extra wrapping, but it was all about it.
    – Aritz
    Feb 25, 2016 at 16:11
  • About every client can process JSON easily. "Almost JSON" is about the worst thing you can do.
    – gnasher729
    Feb 25, 2016 at 23:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.