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

4
  • If I understand correctly you want to pretty print the JSON, right? Commented Sep 6, 2021 at 14:30
  • @SimonMartinelli yes my friend i want a pretty print. Commented Sep 6, 2021 at 14:31
  • 2
    The simplest solution would be to put the formatted JSON in a <pre></pre> block stackoverflow.com/questions/16862627/… Commented Sep 6, 2021 at 14:41
  • @SimonMartinelli can i use it in css-file?? Commented Sep 7, 2021 at 7:39

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

5 Comments

it works thanks but it shows the information in one line !
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..
That doesn't matter where the JSON string comes from. Simply format it before passing it to the HTML component
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.