title: In Which Layer, Dao or Service, Should I Parse a Rest Client Response?
body: <p>I have my own service calling a third party rest service that is returning a text based response.This text based response is not a proper service response and needs to be parsed for content as well as errors. For purposes of discussion, assume the 3rd party rest service cannot be changed.</p>
  <p>Given these circumstance I am wondering whether I should wire that parsing into the dao layer or the service layer of my application.I know that the service layer should contain all of your business logic, but I feel like if I don't do the parsing in my Dao layer I am leaking. Is it ok to have logic in the dao for purposes of parsing/transformation in this case or should it be done in the service layer?</p>
  <p>Any advice is appreciated.</p>
  <pre><code>public void MyDao {
  
       private RestTemplate restTemplate;
       private ResponseParser responseParser;
  
       public myDao(RestTemplate restTemplate, ResponseParser responsePaser){
            this.restTemplate = restTemplate;
            this.responseParser = responseParser;
       }
  
       public MyResponse sendRequest(MyRequest myRequest){
           ResponseEntity&lt;String&gt; responeEntity = restTemplate.exchange(...);
           String body = responseEntity.getBody();
           return responseParser.parse(body);
      }
  }
  </code></pre>
  <p>OR</p>
  <pre><code>public void MyDao {
  
       private RestTemplate restTemplate;
  
       public myDao(RestTemplate restTemplate, ResponseParser responsePaser){
            this.restTemplate = restTemplate;
       }
  
       public String sendRequest(MyRequest myRequest){
           ResponseEntity&lt;String&gt; responeEntity = restTemplate.exchange(...);
           return responseEntity.getBody();
      }
  }
  
  public void MyService {
  
       private MyDao myDao;
       private ResponseParser responseParser;
  
       public myDao(MyDao myDao, ResponseParser responsePaser){
           this.myDao = myDao; 
           this.responseParser = responseParser;
       }
  
       public MyObject process(MyRequest myRequest){
           String response = myDao.sendRequest(myRequest)
           return responseParser.parse(response);
      }
  }
  </code></pre>