我的实体类如下所示:

@Entity
@Table(name = "tbl_programstrm_projstream")
public class ProgramStm_Projstrm_Model {
    @Id
    @GeneratedValue
    private int id;
    @Lob
    @Column(columnDefinition="TEXT")
    private String programstrm;
    private int programstrmId;
    @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
    @JoinColumn(name = "projstrmId")//
    private ProjectStreamModel projstrmId;
//getter and setter
}


基于这个实体,我得到这样的结果json

{
    "programstrm": "D-BSS Implementation",
    "programstrmId": 3,
    "projstrmId": {
      "name": "Program Leadership"
    }
  }


但我希望ProjectStreamModel响应作为字符串而不是作为对象,以便最终结果json看起来像这样”

{
    "programstrm": "D-BSS Implementation",
    "programstrmId": 3,
    "projstrmId": "Program Leadership"

  }

最佳答案

如果我没有正确理解,使用@JsonSerialize可能会帮助您(例如link

07-28 11:42