问题
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