Deserializing JSON with element name containing hyphen
I am writing an Android client that is getting info about a user via a REST-call (JSON).
With Spring the result should be "automagically" returned as in instance of the User object I define, with fields having the same names as the elements in the JSON object.
But one of the elements I am receiving has the name "user-activation-code", and of course I can not create a field with this name in a Java class since Java do not accept hyphens.
How should this be handled?
Code:
try {
HttpBasicAuthentication bAuth = new HttpBasicAuthentication(username,password);
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("Authorization", bAuth.getHeaderValue());
requestHeaders.setAccept(Collections.singletonList(new MediaType("application","json")));
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<User> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, User.class);
User user= responseEntity.getBody();
return user;
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}