我想删除下面的getters和setters样板代码,但我不确定如何删除。我有一个dto类来为json列建模 questionVariables
在我的实体里。
dto公司
import java.io.Serializable;
public class QuestionVariables implements Serializable {
private ScreenOptions screenOptions;
private QuestionOptions questionOptions;
public ScreenOptions getScreenOptions() {
return this.screenOptions;
}
public void setScreenOptions(ScreenOptions screenOptions) {
this.screenOptions = screenOptions;
}
public static class ScreenOptions implements Serializable {
private boolean isSkippable;
public boolean getisSkippable() {
return this.isSkippable;
}
public void setisSkippable(boolean isSkippable) {
this.isSkippable = isSkippable;
}
}
public static class QuestionOptions implements Serializable {
}
}
实体
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Data;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
@TypeDefs({ @TypeDef(name = "json", typeClass = JsonStringType.class) })
@Entity
@Table(name = "questions")
@Data
public class Question {
@JsonSerialize
@JsonDeserialize
@Nullable
@Type(type = "json")
@Column(columnDefinition = "json", nullable = true)
private QuestionVariables questionVariables;
}
我试过使用lombok@getter和@setter注解,但都不起作用。我得到下面的错误
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.Serializable;
@NoArgsConstructor
@Getter
@Setter
public class QuestionVariables implements Serializable {
@NoArgsConstructor
@Getter
@Setter
public static class ScreenOptions implements Serializable {
private boolean isSkippable;
}
@NoArgsConstructor
@Getter
@Setter
public static class QuestionOptions implements Serializable {
}
}
错误
[ERROR] 2021-04-07 10:17:52,484 com.nana.elp.utils.exceptions.DefaultExceptionHandlerAdvice http-nio-8000-exec-2 - Error Code {unknown}, Error Message : java.lang.IllegalArgumentException: The given string value: {
"screenOptions" : {
"isSkippable": true
}
} cannot be transformed to Json object; nested exception is org.hibernate.HibernateException: java.lang.IllegalArgumentException: The given string value: {
"screenOptions" : {
"isSkippable": true
}
} cannot be transformed to Json object
3条答案
按热度按时间nnvyjq4y1#
我很少使用lombok,但我认为应该在属性上使用@getter和@setter注解,而不是类
r8uurelv2#
6ojccjat3#
我不得不补充一句
@JsonDeserialize
到isSkippable
it工作的财产