Error JMSSerializer and UTF-8 (Symfony2.4)

I have a REST api that returns tasks / companies / notes / etc. It works fine on localhost, no matter what task description or company name I write, but I put my application on the server, and when I use characters like "Ε‚ΕΊΔ…ΕΌΔ‡Δ™", there is an error Your data could not be encoded because it contains invalid UTF8 characters." at app/endor/jms/serializer/src/JMS/Serializer/JsonSerializationVisitor.php line 36 .

Databases are the same, tables are the same, all configuration parameters are the same. How can i fix this?

+6
source share
4 answers

I had the same error when I used @VirtualProperty with a method that cut a string using the substr (str, start, length) function. This feature is a bad choice if you are using UTF8. Use mb_substr instead .

+1
source

I have a similar problem, as you can see in my question: Symfony2 and FOSRestBundle: getting UUID in BINARY (16) field from MySQL .

I managed to imagine a binary field converting it to HEX in the log, but the FOSRestBundle still returns the same exception.

Any improvements on your part?

0
source

I found a solution to this problem by setting the database connection properties for data transfer using UTF-8 encoding. This is what the doctrine section looks like in my app/config/config.yml

 doctrine: dbal: default_connection: default connections: default: driver: %database_driver% dbname: %database_name% user: %database_user% host: %database_host% password: %database_password% charset: UTF8 options: 1002: "SET NAMES 'UTF8'" 
0
source

I had the same error message, only in production. It turned out that one row in the database contains the symbol Β¨ , (U + 00A8), which could not be processed by the serializer.

Deleting a character solves the problem.

0
source

All Articles