Converting ZonedDateTime type to Gson
Ich habe einen Rest-Service, der eine Array-Liste des Objekts zurückgibt, und ich habe einen JERSY-Restful-Client implementiert, um es auszuführen, aber ich habe Probleme beim Konvertieren des ZonedDateTime-Typs in JSON, sodass ich diesen Fehler erhalte.
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 231 path $[0].lastmodifieddate
Wie kann ich dieses Problem beheben?
lastmodifieddate-Spalte in Entität
@Column(name = "lastmodifieddate")
private ZonedDateTime lastmodifieddate;
//getter and setter
rest service
@RequestMapping(value = "/getScoreFactor",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public List<Scorefactor> getScoreFactor() throws JSONException {
return scoreService.getScoreFactor();
}
jersy erholsamer Client
try {
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/adap/api/getScoreFactor");
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
String output = response.getEntity(String.class);
System.out.println("output--"+output);
Type listType = new TypeToken<List<Scorefactor>>() {}.getType();
List<Scorefactor> scorefactors = new Gson().fromJson(output,listType);
System.out.println(scorefactors);
} catch (Exception e) {
e.printStackTrace();
}