I have a table in PostgreSQL with 2 columns - Id and coord. Column "coord" - geo coordinates stored as a string in JSON format.
Example:
[{"lat":49.09693425316379,"lng":33.61747393628419},{"lat":49.11835977646441,"lng":33.638456496907},{"lat":49.12103137811804,"lng":33.63866144845382},{"lat":49.09694682809236,"lng":33.61746879914138},{"lat":49.08920750204137,"lng":33.61734796797724},{"lat":49.07643862058337,"lng":33.61246117651179}]
How to send such string as JSON Array of objects(POST request).
Entity without getters and setters
public class Lepcoord implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 30)
@Column(name = "tplnr")
private String tplnr;
@Size(max = 2147483647)
@Column(name = "coord")
private String coord;
Controller
@POST
@RequestMapping(value= "/lep/{voltage}", method = RequestMethod.POST, headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<List<Lepcoord>> lep (@PathVariable String voltage)
{
return new ResponseEntity<>(gisDaoService.lep(voltage), HttpStatus.OK);
}
And service
@Transactional(readOnly = true)
public List <Lepcoord> lep (String voltage) {
Query query = this.em.createQuery(
" From Lepcoord ");
List <Lepcoord> rez = null;
try {
rez = (List<Lepcoord>) query.getResultList();
} catch (PersistenceException r) {
return null;
}
return rez;
}
Hibernate cant handle json type If i storeing coord as json in Postgre. May be someone knows easier way. Not to write own classes to work with Postgres json type