Neno0o
Neno0o

Reputation: 133

Retrofit Gson deserialize string special characters

I have that json

[
  {
    TITLE: "Yoy’s Child"
  },
    TITLE: "Look at me – Stop looking"
  }
]

I use retrofit and gson and the results are

Yoy’s Child
Look at me – Stop looking

The problem is encoding that special characters. Here's my code

GsonBuilder gsonBuilder = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
                public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
                    return new Date(json.getAsJsonPrimitive().getAsLong());
                }
            });

    gson = gsonBuilder.create();

    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(WEB_URL)
            .setConverter(new GsonConverter(gson))
            .build();

    apiService = restAdapter.create(APIService.class);

Upvotes: 0

Views: 1506

Answers (2)

Neno0o
Neno0o

Reputation: 133

I solved it. I debugged the application and found out that the return json had the symbol issues. All I had to do was just to encode json to UTF-8.

Upvotes: 0

Adam W
Adam W

Reputation: 1012

Try adding the disableHtmlEscaping command to the GsonBuilder constructor.

GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping();

Upvotes: 2

Related Questions