Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Splecial characters in RTE are displayed differently after conversion to JSON view

Avatar

Level 2

1. Created a custom component dialog, which has field='Answer Text' with richtext field

1681730_pastedImage_0.png

2. Gave Special characters as input

1681736_pastedImage_3.png

1681731_pastedImage_1.png

3. Create Sling Model Exporter for JSON output

@PostConstruct

public void invokepost() {

if (answerText != null && !answerText.isEmpty()) {

answerText = formatAnswerRTEText(answerText);

}

}

// In this method, rteText is passed as a parameter which needs to be trimmed and covered with double quotes and remove all the new lines in the text

private String formatAnswerRTEText(String rteText) {

String modifiedRteText = null;

modifiedRteText = "\"" + rteText.trim() + "\"";

modifiedRteText = modifiedRteText .replaceAll("\\r|\\n", "");

return modifiedRteText ;

}

4. JSON output is not displaying special characters

1681737_pastedImage_8.png

Please guide me in resolving this issue. (Special characters should be displayed as it is in JSON output)

12 Replies