JAVA MessageFormat.Format with umlauts (ä / ö / ü)

1k views Asked by At

I have a problem with MessageFormat.format in my Java backend. I have there a mailing function which sends mails with content from my frontend (passend via api to the backend) to some users.

String text =
    MessageFormat.format(
        "Dear Report Owner\n\nA new access request:\n\nFrom: {0} {1} ({2})\nFor: {3} \nReason: {4}\n\nPlease process the access request and inform {0} {1} accordingly.\n\nBest regards,\nDev-Team",
        accessTokenUser.getGivenName(),
        accessTokenUser.getFamilyName(),
        accessTokenUser.getEmail(),
        processedRoleContent,
        processedLinkContent);

It's possible, that some values (e.g. processedRoleContent) contains for example ü but in the sent email it appears as Ü.

How can I configure the MessageFormat.format that it send's umlauts?

Thank you in advance!

2

There are 2 answers

3
Obyvante On

You can convert byte then UTF-8 for any kind of String.

new String(out.toByteArray(), "UTF8")
0
Smutje On

Consider the following minimal demonstration of why I think MessageFormat.format has nothing to do with your problem:

import java.text.MessageFormat;

public class Application {

    public static void main(String[] args) {
        System.out.println(MessageFormat.format("{0}", "ü"));
    }
}

which results at my machine in the output ü.

So, I think your E-Mail function escapes Umlauts as HTML entities.