Deserialization problem UpperCase

235 views
Skip to first unread message

Giuseppe

unread,
Oct 26, 2012, 10:58:11 AM10/26/12
to googl...@googlegroups.com
Our web service return JSON string with property name in uppercase.

In our Java (Android) client we use GSON to deserialize it and cast to a POJO class.

Sometime the deserialization fail because the name of a property from the WebService is USERNAME and on the client side the JAVA class have userName

Anyway to avoid this problem ?

Thanks in advance
Giuseppe

Bram

unread,
Oct 30, 2012, 10:00:34 AM10/30/12
to googl...@googlegroups.com
You can solve this by using the SerializedName annotation. E.G.

import com.google.gson.annotations.SerializedName;

public class User {
    @SerializedName("USERNAME")
    private String userName;
}

Op vrijdag 26 oktober 2012 16:58:11 UTC+2 schreef Giuseppe het volgende:
Reply all
Reply to author
Forward
0 new messages