将内部json对象转换为字符串

时间:2017-05-27 16:22:55

标签: java json spring

我的实体类看起来像这样:

@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"

  }

1 个答案:

答案 0 :(得分:0)

如果我感觉不对,使用@JsonSerialize可能会对你有所帮助(例如link