Jackson ObjectMapper with UTF-8 encoding?

Jackson automatically detects encoding used in source: as per JSON specification, only valid encodings are UTF-8, UTF-16 and UTF-32. No other encodings (like Latin-1) can be used.
Because of this, auto-detection is easy and done by parser — no encoding detection is accepted for this reason.
So, if input is UTF-8, it will be detected as such.

For output, UTF-8 is the default; but if you explicitly want to use another encoding, you can create JsonGenerator explicitly (with a method that takes JsonEncoding), and pass this to ObjectMapper.

Alternatively in both cases you can of course manually construct java.io.Reader / java.io.Writer, and make it use whatever encoding you want.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)