小编fra*_*ail的帖子

强制GSON使用特定的构造函数

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 …
Run Code Online (Sandbox Code Playgroud)

java constructor gson deserialization

20
推荐指数
2
解决办法
1万
查看次数

标签 统计

constructor ×1

deserialization ×1

gson ×1

java ×1