How can I return JSON responses with Dropwizard healthcheck?

China☆狼群 提交于 2019-12-11 04:56:24

问题


I've been working on adding healthchecks to my dropwizard service. The problem is dropwizard returns plain text responses when I run my healthchecks. And I can only add an optional string messages to this output.

For example: * Available Disk Space: OK Disk usage is not critically high (my message string) * Available Memory: OK * CPU Usage: OK * deadlocks: OK

Is there a way to return these messages in JSON format so that I can parse the output easily?

Thanks a million!


回答1:


You can pass ObjectMapper to your healthcheck. Then you can use appropriate methods such as com.fasterxml.jackson.databind.ObjectMapper#writeValueAsString of ObjectMapper and pass String argument to create a healthcheck instance.




回答2:


If possible, upgrade to Dropwizard v0.7.1. The default health check format will be JSON.



来源:https://stackoverflow.com/questions/18981107/how-can-i-return-json-responses-with-dropwizard-healthcheck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!