Jackson ObjectMapper with UTF-8 encoding?
jackson, json
Solution
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.
Problem
Is there a way to tell Jackson to use UTF-8 encoding when using `ObjectMapper` to serialize and deserialize Objects?