2016-06-30 3 views
0

私はこのサービスをdbから特定のユーザーに持ち、jsonオブジェクトとして返します。
私は応答を受信し、JSONとしてそれを使用したいが、私は私は私がこれを取得レスポンス印刷する場合は間違って何か原因をしたことはほぼ100%確信している:ResponseEntityがjava.lang.Objectを返す

[Ljava.lang.Object;@69a38065 


をこれは、コントローラ:

public Object[] getClienteNomeCognome(String nome, String cognome) throws Exception { 
    try { 
     final RestTemplate restTemplate = new RestTemplate(); 
     final String url = "somelink?cognome=%25"+cognome+"%25&nome=%25"+nome+"%25"; 
     //final ResponseEntity<List> response = (ResponseEntity<List>) restTemplate.getForObject(url, List.class); 
     final ResponseEntity<Object[]> response = restTemplate.getForEntity(url, Object[].class); 
     Object[] risultati = response.getBody(); 
     LOGGER.info("La richiesta e' stata effettuata con status code: " + response.getStatusCode().toString()); 
     if (risultati != null && risultati.toString().contains("<error>")) { 
      throw new Exception(String.format(
        "[SERVICE] La risposta del servizio contiene degli errori: %s", 
        risultati)); 
     } else { 
      LOGGER.debug("[SERVICE] Fine chiamata al servizio di ricerca cliente"); 
      LOGGER.info(response.getBody().toString()); 
      return risultati; 
     } 
    } catch (HttpClientErrorException hcee) { 
     throw new Exception(String.format(
       "[SERVICE] Errore durante la chiamata. Error: %s", 
       hcee.getMessage())); 
    } catch (Exception e) { 
     throw new Exception(String.format(
       "[SERVICE] Errore generico durante la chiamata al servizio. Error: %s", 
         e.getMessage())); 
    } 

} 

答えて

0

あなたはObjectクラスにオーバーロードされていないのtoString()の結果を、表示しています。したがって、オブジェクトの名前と住所を表示します。

結果を格納するためにクラスを使用する必要があります。また、toString()をオーバーロードして意味のある表現をすることができます。

また、あなたは結果を表示するには、強く型付けされたリストを使用することができます。

ResponseEntity<List<YourEntity>> yourResponse = restTemplate.exchange("https://some-link/your-object-location", 
       HttpMethod.GET, null, new ParameterizedTypeReference<List<YourEntity>>() { 
     }); 
List<YourEntity> entities = yourResponse .getBody(); 
+0

私はサービスが返されますどのような情報についてはよく分からないので、私はクラスを実装したくないと思いますので、私は解決策を必要としますそれは私がjsonオブジェクトで操作できるように、私は角度ngrepeatのようなもので情報を回復することができます... –

関連する問題