I'm working on a REST API with Symfony2 which receives data in JSON format.
Where is the right place to convert JSON to objects:
It definitely doesn't belong to the service layer because it's supposed to work in terms of model objects. You can have lots of different UIs in an application — HTML, REST, command line — and all of them will use different formats for data exchange. Making the service layer responsible for handling all these formats doesn't make sense.
Each type of UIs has its own layer of controllers — or commands in the case of a command line UI — and it's the responsibility of those controllers to convert data to and from model objects before passing them to the service layer and back.
How exactly you do that — directly in controller actions, or delegating to other services, or using AOP — is your choice. Just keep it out of the service layer — domain layer, that is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With