private JsonEncoding getEncoding(MediaType contentType) {
   if (contentType != null && contentType.getCharSet() != null) {
     Charset charset = contentType.getCharSet();
     for (JsonEncoding encoding : JsonEncoding.values()) {
       if (charset.name().equals(encoding.getJavaName())) {
         return encoding;
       }
     }
   }
   return JsonEncoding.UTF8;
 }
Exemple #2
0
 protected Writer _createWriter(OutputStream out, JsonEncoding enc, IOContext ctxt)
     throws IOException {
   // note: this should not get called any more (caller checks, dispatches)
   if (enc == JsonEncoding.UTF8) { // We have optimized writer for UTF-8
     return new UTF8Writer(ctxt, out);
   }
   // not optimal, but should do unless we really care about UTF-16/32 encoding speed
   return new OutputStreamWriter(out, enc.getJavaName());
 }