Answer the question
In order to leave comments, you need to log in
Remove quote escaping in json response of Spring+Hibernate+Postgresql?
I am writing a microservice using spring-boot+hibernate+psql
View data structure.
id, UserID type int, UserProfile type json.
The first two are clear.
The UserProfile contains an object of type json -
"{ "name": "Book the First", "author": { "first_name": "Bob", "last_name": "White"} }"
@Column(name="UserProfile")
private String userProfile;
public String getUserProfile() {
return userProfile;
}
{ \"name\": \"Book the First\", \"author\": { \"first_name\": \"Bob\", \"last_name\": \"White\" } }
Answer the question
In order to leave comments, you need to log in
you need to work out the transport object, which will be mapped to / from the JSON representation.
Or it’s cheap and cheerful to work with Map, then you can do it like this:
@Inject
private JsonParser jsonParser;
@RequestMapping(value="/user_profile/{id}", method = RequestMethod.GET)
public ResponseEntity<Map<String, Object>> get(@PathVariable("id") Long id) {
UserEntity entity = userRepository.get(id);
Map<String, Object> profile = jsonParser.parseMap(entity.getUserProfile());
return new ResponseEntity(profile, HttpStatus.OK);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question