Vorab: Ja, es gibt @RequestBody. Und es ist hässlich. Ich habe es nicht mal eingebaut. Aber ich musste es googlen und will das nicht noch mal tun müssen:
1 2 3 4 5 6 7 8 9 10 |
private Long extractFooBarFromRequest() { if ("POST".equalsIgnoreCase(request.getMethod())) { try { String jsonString = CharStreams.toString(request.getReader()); JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject(); return jsonObject.get("fooBar").getAsLong(); } catch (Exception ignore) {} } return null; } |
PS zu Zeile 2 und zu Zeile 4.