Сокращение кода шаблона (геттеры и сеттеры) в классе моделирования DTO [closed]

Я хотел бы удалить шаблонный код геттеров и сеттеров ниже, но я не знаю, как это сделать. У меня есть класс 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

0

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *