Skip to content

Manage charset problems

xcesco edited this page Dec 23, 2020 · 1 revision

When you work with Retrofit and web services, you are probably (I hope so) working with UTF-8. Just remember that JSON RFC specifies to with it. In somecase I had to manage incorrect situation without change the backend behaviour (the server produce JSON is no UTF-8).

Jackson library in its default behaviour throw an exception. To control this, since kripton 7-rc.9, it is possible to specify the error action to manage charset errors and what are the expected charset.

An example:

Retrofit retrofit = new Retrofit.Builder()
  .baseUrl("https://jsonplaceholder.typicode.com")
  .addConverterFactory(KriptonBinderConverterFactory.Builder.create()
    .setDefaultCharset(StandardCharsets.UTF_8)
    .setErrorAction(CodingErrorAction.IGNORE)
    .build())
  .build();

With setDefaultCharset you can specify the charset used to decode incoming stream (response body) and outcoming stream (request body). With setErrorAction you specify how to manage unexpected char. The default value for error action is IGNORE (the wrong char is deleted, without exception).

Some links

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally