ho questo:Come posso aggiungere intestazioni a una risposta da scintilla, quando si utilizza un trasformatore
get ("/test", (req, resp) -> {
return repository.getAll();
}, new JsonTransformer());
mio trasformatore assomiglia:
public class JsonTransformer implements ResponseTransformer {
ObjectMapper om = new ObjectMapper();
public JsonTransformer() {
}
@Override
public String render(Object o) throws Exception {
return om.writeValueAsString(o);
}
}
Ho provato ad aggiungere un colpo di testa utilizzando la intestazione funtion sulla risposta in questo modo:
get ("/test", (req, resp) -> {
resp.header("Content-Type", "application/json");
return repository.getAll();
}, new JsonTransformer());
e ho provato questo che ho trovato nella documentazione: Penso thi s imposta il accetta di tipo
get ("/test", "application/json", (req, resp) -> {
return repository.getAll();
}, new JsonTransformer());
Ma da nessuna parte sto ottenendo application/json
come il mio Content-Type
intestazione
vorrei pensare di cambiare il tag scintilla. Questo sembra essere per il quadro di calcolo della scintilla apache, non per il framework ws. – grinch
aah grazie farà – albertjan
Come l'hai risolto? Ho aggiunto "response.type (" application/json ");" Funziona, ma c'è un modo più bello? – Gabriel