I'm using content-negotiation, so depending on the header of the request I provide JSON/XML output. Now I was wondering what the best location is for providing this functionality.
Info:
BLL= business logic layer
DTO= data transfer object
DAL= data access layer
Pseudo-Code example for DTO
class ExampleDTO{
propertie name;
propertie description;
}
Pseudo-Code example for BLL
class ExampleBLL{
GetExample(name) returns ExampleDTO;
GetExamples() returns List<ExampleDTO>;
}
1) In the GUI with a BLL-object: transforms the DTO result from the BLL into JSON/XML
2) In the BLL: something like... getObjectJSON() -> transforms & returns DTO-input into a JSON format
3) In the DTO: behavior like... toJSON() toXML() like a toString()
4) Or extra DTO's with only 1 propertie (json/xml)
5) Something else? ...
*Personally I think (1) is wrong for the reason to keep logic out of GUI, (4) seems overkill to have extra DTO's like WebJsonExampleDTO AND a WebXmlExampleDTO with only one propertie