Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gson serialization error class com.activeandroid.DatabaseHelper declares multiple JSON fields named mContext

The error im getting is "java.lang.IllegalArgumentException: class com.activeandroid.DatabaseHelper declares multiple JSON fields named mContext"

I am using AndroidAnnotations RestClient to pull data from my Web Service and serialize into POJOs. The serializations worked fine while using ORMLite but i recently decided to try out Active Android and now my classes extends Model. Gson is serializing the parent class which i have no control over. Any way I can only include certain fields or maybe just return plain JSON from the RestClient and do the serialization a different way

@Rest(rootUrl = "http://stuff...com", converters = { GsonHttpMessageConverter.class })
    public interface RestClient {
    @Get("/AndroidController/createFacebookUser?facebookToken={facebookToken}&catIds=    {catIds}")
    User createFacebookUser(String facebookToken,String catIds);
}

and the User model is

@Data
@Table(name = "Users")
public class User extends Model {
@Column(name = "SystemID")
private String systemID;
@Column(name = "Name")
private String name;
public List<GameEntry> items() {
    return getMany(GameEntry.class, "Category");
}

public User(){}

}

like image 578
Darussian Avatar asked Mar 12 '13 04:03

Darussian


1 Answers

Gson provides multiple ways of excluding fields and types from Serialization and Deserialization. Take a look at Excluding Fields From Serialization and Deserialization, specifically the usage of @Expose annotation and user-defined ExclusionStrategy.

like image 131
Rajesh Avatar answered Oct 16 '22 16:10

Rajesh