0

I have a Spring Boot console application and I access the actuator endpoints over JMX. The problem is that the returned text is not pretty-printed and it's not JSON. It looks something like this:

{context=application, parent=null, beans=[{bean=helloWorldApplication, scope=singleton, type=com.surpreso.spring_skeleton.HelloWorldApplication, resource=null, dependencies=[helloWorldService]}, {bean=helloWorldService, scope=singleton, type=com.surpreso.spring_skeleton.HelloWorldService, resource=file [C:/src-tmp/spring-skeleton/target/classes/com/surpreso/spring_skeleton/HelloWorldService.class], dependencies=[]}, {bean=com.surpreso.spring_skeleton.DefaultConfig,  ...

What the best way to get this into a readable format? Is it possible to configure the JMX actuator to pretty-print? Is it possible to configure the JMX actuator to use JSON?

There's a related question about Pretty print JSON output of Spring Boot Actuator endpoints, but in this case I'm stuck with JMX because I don't have a web application. As the next step I'll try CRaSH, but I was curious if I can configure the JMX actuator to be more usable.

I'm using version 1.2.5 of Spring Boot.

UPDATE: The CRaSH implementation uses the same format, so it's not a solution.

UPDATE 2: I see this commit in 1.3.0 about "Use configured ObjectMapper, if available, in all EndpointMBeans" but I don't know what properties to set for pretty printing. It's close ...

UPDATE 3: spring.jackson.serialization.indent_output=true did not have any effect through the CRaSH interface. I'm on 1.3.0.M2 now.

Community
  • 1
  • 1
Bogdan Calmac
  • 7,993
  • 6
  • 51
  • 64

1 Answers1

2

The output that you pasted is a valid json document. What makes you think it's invalid exactly?

If you want to pretty print the format, it really depends how you are accessing your JMX endpoint. If you are accessing it via JConsole for instance, I am not sure that a pretty printed output will be much readable with large documents. If you are accessing the JMX endpoint manually then you can read the String and pretty print the output very easily (JSONObject has a toString method that takes the indent you want to apply on the document).

Regarding CRaSH, that's unrelated really. Actuator endpoints live outside of CRaSH and doesn't use any of its feature.

EDIT: My mistake, this isn't valid JSON, I have created #3658 in the Spring Boot issue tracker.

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
  • You could say it's JSON-like, but it's not JSON. Strings are not quoted and ":" is replaced with "=". See http://json.org/example. – Bogdan Calmac Aug 03 '15 at 17:19
  • Regarding the usage, I'd access the JConsole or CRaSH shell interactively and then I want to somehow make sense of the data. It would be just fine if the output is valid JSON that I can paste in an editor and pretty-print it. – Bogdan Calmac Aug 03 '15 at 17:20
  • Oh well, I thought it was JSON but I didn't look closely enough, sorry about that! I have created [3658](https://github.com/spring-projects/spring-boot/issues/3658), thanks! – Stephane Nicoll Aug 04 '15 at 12:08