Force GSON à l'utilisation spécifique du constructeur

public class UserAction {
    private final UUID uuid;
    private String userId;
    /* more fields, setters and getters here */

    public UserAction(){
        this.uuid = UUID.fromString(new com.eaio.uuid.UUID().toString());
    }

    public UserAction(UUID uuid){
        this.uuid = uuid;
    }
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final UserAction other = (UserAction) obj;
        if (this.uuid != other.uuid && (this.uuid == null || !this.uuid.equals(other.uuid))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.uuid != null ? this.uuid.hashCode() : 0);
        return hash;
    }
}

Je suis à l'aide de Gson à serilize et désérialiser cette classe. Comme aujourd'hui, j'ai dû ajouter un final UUID dans cet objet. Je n'ai pas de problème de sérialisation. J'ai besoin de force gson à utiliser public UserAction(UUID uuid) constructeur lors de la désérialisation. Comment puis-je y parvenir ?

OriginalL'auteur frail | 2011-05-31