I have a REST controller whice should return a list of companies in json format. The companies are fetched by a service. Where should i encode the result into json format? I tought of an encoder class, but where should i inject that?
Asked
Active
Viewed 122 times
0
-
In the same place where you would turn the list of companies in a HTML list: template. That's what view instance are using to assemble the response. – tereško Sep 04 '14 at 05:33
1 Answers
-1
PHP Offers JSON encoding / decoding functionality built in:
http://php.net/manual/en/function.json-encode.php
$json_result = json_encode($array_to_be_encoded);

Nathan Matthews
- 81
- 1
- 4
-
Yep, i know that, but my service returns an object instead of an array. My question is where i should encode the result. In the service or in the controller? – Dominik Barann Sep 03 '14 at 06:50
-
I would imagine the Service layer would be best suited for JSON encoding. – Nathan Matthews Sep 10 '14 at 17:25