1

I have a Dialog that retrieve informations from an endpoint (String of information) but I have a Problem with style this dialog, because all these informations appear untidily!

For example to be clear, I have this endpoint, that it helps me to retrieve a Data about Mobile, and want to show this Data in a Dialog (BUT the Style should like Screenshot Nr. 1), but my Problem is that the data appears as Preview (Screenshot 2).

enter image description here

bad_coder
  • 11,289
  • 20
  • 44
  • 72
albo
  • 25
  • 2

1 Answers1

1

You can use the Html component with a pre tag where you put the formatted JSON:

Html pre = new Html("<pre>" + formattedJson + "</pre>");

To format the JSON String you can use this:

String prettyJson = mapper.writerWithDefaultPrettyPrinter()
                          .writeValueAsString(mapper.readTree(inputJson));

Find more examples here: https://roytuts.com/how-to-pretty-print-json-in-java/

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
  • it works thanks but it shows the information in one line ! – albo Sep 07 '21 at 10:25
  • Have you formatted the JSON? https://roytuts.com/how-to-pretty-print-json-in-java/ – Simon Martinelli Sep 07 '21 at 11:57
  • no because i read the data from an endpoint (not directly from JOSN file) and the Data be able to change. i mean i want to call the endpoint to show the data.. – albo Sep 07 '21 at 14:45
  • That doesn't matter where the JSON string comes from. Simply format it before passing it to the HTML component – Simon Martinelli Sep 07 '21 at 14:59
  • can u show me an example if the data comes from an endpoin and then how to pass it !! am so sorry but am new in this .. and thanks. – albo Sep 08 '21 at 09:18