Alex Rivera | Logout

How to expose a method using GSon?

Asked 2011-09-14T12:25:31.497
25

Using Play Framework, I serialize my models via GSON. I specify which fields are exposed and which aren't.

This works great but I'd also like to @expose method too. Of course, this is too simple.

How can I do it ?

Thanks for your help !

public class Account extends Model {
    @Expose
    public String username;

    @Expose
    public String email;

    public String password;

    @Expose // Of course, this don't work
    public String getEncodedPassword() {
        // ...
    }
}
Edit
Report

1 Answer

7

Gson's @Expose seem to only be supported on fields. There is an issue registered on this: @Expose should be used with methods.

answered 2011-09-14T17:53:15.767

Your Answer