Partly UTF-8 Garbled Issue

Partly UTF-8 Garbled Issue

When I was deploying my service to the server today, which is a debian 9 linux node, I met a strange issue. The service is made with spring boot framework, running with jvm.

The response of api when I running locally:

{
    "statusCode": "200",
    "statusMessage": "成功!",
    "data": {
        "classId": 1,
        "className": "三年二班",
        "maxRoom": 1.0000000000
    },
    "message": null,
    "timeStamp": 1609514106583
}

But the server returns

{
    "statusCode": "200",
    "statusMessage": "����!",
    "data": {
        "classId": 1,
        "className": "三年二班",
        "maxRoom": 1.0000000000
    },
    "message": null,
    "timeStamp": 1609514106583
}

The statusMessage is garbled. However, the data.className keeps a normal behavior.

As the response body is partly garbled, the issue can be speculated as the java file was not compiled with encoding utf-8.

try add

-Dfile.encoding=UTF-8

to the end of /etc/profile.

Then

mvn package

Finally, the response body return to normal.

"statusMessage": "成功!",