1
JSON形式で2倍の値を返す、以下に示すような動作中のWebサービスがあります。今{"PMC":17.34}
表現からJSONをキャプチャして文字列値を返す
@Override
@Post("JSON")
public Representation post(Representation entity) throws ResourceException
{
JsonObjectBuilder response = Json.createObjectBuilder();
try {
String json = entity.getText(); // Get JSON input from client
Map<String, Object> map = JsonUtils.toMap(json); // Convert input into Map
double result = matrix.calculatePMC(map); // Calculate PMC value
response.add("PMC", result);
} catch (IOException e) {
LOGGER.error(this.getClass() + " - IOException - " + e);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
}
return new StringRepresentation(response.build().toString());
}
、私は二重の値、すなわち17.34
を返すようにプログラムを変更したいので、私は次のように私のプログラムを修正:
@Post
public double post(Response response)
{
double result = 0;
try {
String json = response.getEntity().getText(); //Get JSON input from client
Map<String, Object> map = JsonUtils.toMap(json); // Convert input into Map
result = matrix.calculatePMC(map); // Calculate PMC value
} catch (IOException e) {
LOGGER.error(this.getClass() + " - IOException - " + e);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
}
return result;
}
私はこれを実行すると、私が得ます415 Unsupported Media Type
エラー。私は何が欠けていますか?
'@post(「JSON」)公共ダブルpostImpl(文字列のJSON)'に '@post公共ダブルポスト(レスポンスレスポンス)'に変更し、あなたが得たものを教えてください。 –
正しい方向に私を向けるために@AbhishekOzaをありがとう! – Maruli