Я сердцебиения API implemeted с помощью сервиса Spring REST:Как сделать заголовок Content-Type необязательным?
@RequestMapping(value = "heartbeat", method = RequestMethod.GET, consumes="application/json")
public ResponseEntity<String> getHeartBeat() throws Exception {
String curr_time = myService.getCurrentTime();
return Util.getResponse(curr_time, HttpStatus.OK);
}
И MyService.java имеет ниже метод:
public String getCurrentTime() throws Exception {
String currentDateTime = null;
MyJson json = new MyJson();
ObjectMapper mapper = new ObjectMapper().configure(SerializationConfig.Feature.DEFAULT_VIEW_INCLUSION, false);
try {
Date currDate = new Date(System.currentTimeMillis());
currentDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(currDate);
json.setTime(currentDateTime);
ObjectWriter writer = mapper.writerWithView(Views.HeartBeatApi.class);
return writer.writeValueAsString(json);
} catch (Exception e) {
throw new Exception("Excpetion", HttpStatus.BAD_REQUEST);
}
}
Это работает, как ожидалось, но есть 2 проблемы:
Когда я вызываю этот API, заголовок Content-Type является обязательным & Я хочу знать, как сделать этот заголовок необязательным.
Как добавить заголовок «Принять», чтобы он мог поддерживать другой формат, такой как Google Protobuf?
Спасибо!