Last active
March 14, 2016 05:21
-
-
Save marsyang1/ed17ad9a3dad3d6983e6 to your computer and use it in GitHub Desktop.
Java unicode to char
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* http://stackoverflow.com/questions/11145681/how-to-convert-a-string-with-unicode-encoding-to-a-string-of-letters | |
* use StringEscapeUtils.unescapeJava(encodeUniCode String) | |
*/ | |
@Component | |
public class RestClient { | |
private final RestTemplate restTemplate; | |
public RestClient(){ | |
restTemplate = new RestTemplate(); | |
HttpHeaders headers = getJsonHeader(); | |
} | |
public HttpHeaders getJsonHeader(){ | |
HttpHeaders headers = new HttpHeaders(); | |
headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); | |
return headers; | |
} | |
public String exchangeToString(String url, HttpMethod method) { | |
return exchangeToString(url,method,getJsonHeader()); | |
} | |
public String exchangeToString(String url, HttpMethod method , HttpHeaders headers) { | |
HttpEntity<String> requestEntity = new HttpEntity<>(headers); | |
ResponseEntity<String> response = | |
restTemplate.exchange(url, method, requestEntity, String.class); | |
String body = response.getBody(); | |
return StringEscapeUtils.unescapeJava(body); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment