Issue
- When inserting emojis (emoticons) to a Web Content article, the portal fails to add/update the article and an error similar to the one below is shown on logs.
09:33:30.544 ERROR [http-nio2-8080-exec-48][JDBCExceptionReporter:234] Incorrect string value: '\xF0\x9F\x98\x8D\xE2\x9D...' for column 'content' at row 1
Environment
- Liferay DXP 7.x
Resolution
- While Liferay DXP supports emoji, changes must be made to both the database and to the
portal-ext.properties
DB connection string. This article deals the procedure with MySQL only, but similar solutions are available to other RDBMS. - Create the database with the character set
utf8mb4
instead ofutf8
(which is an alias forutf8mb3
). Example:
CREATE DATABASE `lportal` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
- Create the tables with the charset
utf8mb4
instead ofutf8
. Example:
CREATE TABLE `tablename` (
(...)
PRIMARY KEY (`primaryKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;
- If the database already exists, dump it with
mysqldump
and replace the parametersDEFAULT CHARSET=utf8;
toDEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;
for eachCREATE TABLE
query. - Change the property
jdbc.default.url
fromportal-ext.properties
replacing the parametercharacterEncoding=UTF-8
touseUnicode=true
.
Additional Information
- LPS-43195: Exception occurred when input "emoji" as content on mobile device