title: How to return an json object when request is OK, and a json error object when failing in SpringBoot
body: <p>I have a method:</p>
  <pre><code>@RequestMapping(value = &quot;/Commande&quot;, method = RequestMethod.GET)
  public String authorizeMeter(...){
      try {
          MyObject result = port.commanderCollectePublicationMesures(demande);
      } catch (Erreur erreur) {
          return erreur;
      }
  }
  </code></pre>
  <p>When the request is successful, I will get a MyObject result, and when I catch an error, and Erreur Object.</p>
  <p>In the end, both of the response will be serialized, so, it will all be JSON.</p>
  <p>This is if I put: <code>String</code> return type, compiler doesn't like it saying, I must return MyObject Type, or Erreur Type</p>
  <p>If I have only 1 type ( MyObject ), Springboot will automatically serialize it to JSON which is great.</p>
  <p>But how should I manage Erreur message?</p>
  <p>Should I always convert myself the object into JSON?</p>