0

I want add two names on "id". like @JsonProperty("value") and @JsonProperty("id") How to do it?

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "trainingProgramId", unique = true, nullable = false)
public class TrainingProgram {
    `private Integer id;`
    public Integer getId() {
        return this.id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
}
Norbert
  • 2,741
  • 8
  • 56
  • 111
Bruce
  • 11
  • 2
  • 1
    Possible duplicate of [JSON Jackson parse different keys into same field](http://stackoverflow.com/questions/19564711/json-jackson-parse-different-keys-into-same-field) – rorschach Sep 28 '16 at 06:19

1 Answers1

0

You could probably duplicate the value of id into another attribute with another name.

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "trainingProgramId", unique = true, nullable = false)
public class TrainingProgram {
    private int id;
    private int idDupe;

    public TrainingProgram() {
        idDupe = id;
    }

    public int getIdDupe() {
        return this.idDupe;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }
}

But the better question would be: Why do you need the duplicated id value? Wouldn't it be a better design if the caller could directly use the id instead the duplicate?

nihaf
  • 1
  • 1
  • 3