Java反序列化成list对象集合_Spring Boot - 反序列化对象列表中的对象

我有一个对象作为问题 . 在问题对象里面我有主题列表 . 当我试图发布这个控制器的请求时,我得到的主题列表为空 . 我试图验证swagger用户界面,我无法在列表中看到任何参数 .

Question.java

import java.io.Serializable;

import java.util.Date;

import java.util.List;

import javax.persistence.CascadeType;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import javax.persistence.JoinColumn;

import javax.persistence.JoinTable;

import javax.persistence.ManyToMany;

import javax.persistence.OneToMany;

import javax.persistence.OneToOne;

import javax.validation.constraints.NotNull;

import org.hibernate.annotations.CreationTimestamp;

@Entity

public class Question implements Serializable {

@Id

@GeneratedValue(strategy=GenerationType.SEQUENCE)

@Column(name="questionId")

private Integer questionId;

@NotNull

@Column(name="title")

private String title;

@NotNull

@Column(name="body")

private String body;

@CreationTimestamp

private Date createdAt;

@CreationTimestamp

private Date modifiedAt;

@OneToOne

@JoinColumn(name="userId")

private User userId;

@OneToMany(cascade=CascadeType.ALL)

@JoinColumn(name="question_id")

private List commentList;

@ManyToMany(cascade=CascadeType.ALL)

@JoinTable(name="Question_topic",

joinColumns=@JoinColumn(name="question_id"),

inverseJoinColumns=@JoinColumn(name="topic_id"))

private List topicList;

/**

* @return the questionId

*/

public Integer getQuestionId() {

return questionId;

}

/**

* @param questionId the questionId to set

*/

public void setQuestionId(Integer questionId) {

this.questionId = questionId;

}

/**

* @return the title

*/

public String getTitle() {

return title;

}

/**

* @param title the title to set

*/

public void setTitle(String title) {

this.title = title;

}

/**

* @return the body

*/

public String getBody() {

return body;

}

/**

* @param body the body to set

*/

public void setBody(String body) {

this.body = body;

}

/**

* @return the createdAt

*/

public Date getCreatedAt() {

return createdAt;

}

/**

* @param createdAt the createdAt to set

*/

public void setCreatedAt(Date createdAt) {

this.createdAt = createdAt;

}

/**

* @return the modifiedAt

*/

public Date getModifiedAt() {

return modifiedAt;

}

/**

* @param modifiedAt the modifiedAt to set

*/

public void setModifiedAt(Date modifiedAt) {

this.modifiedAt = modifiedAt;

}

/**

* @return the userId

*/

public User getUserId() {

return userId;

}

/**

* @param userId the userId to set

*/

public void setUserId(User userId) {

this.userId = userId;

}

/**

* @return the commentList

*/

public List getCommentList() {

return commentList;

}

/**

* @param commentList the commentList to set

*/

public void setCommentList(List commentList) {

this.commentList = commentList;

}

public List getTopicList() {

return topicList;

}

public void setTopicList(List topicList) {

this.topicList = topicList;

}

}

Topic.java

import java.io.Serializable;

import java.util.Date;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import javax.persistence.JoinColumn;

import javax.persistence.OneToOne;

import org.hibernate.annotations.CreationTimestamp;

@Entity公共类主题实现Serializable {

/**

*

*/

private static final long serialVersionUID = 1L;

@Id

@GeneratedValue(strategy=GenerationType.SEQUENCE)

@Column

private Integer topicId;

@Column

private String topicName;

@Column

private String topicDesc;

@CreationTimestamp

private Date createdAt;

@OneToOne

@JoinColumn(name="userId",insertable=false,updatable=false)

private User userId;

/**

* @return the topicId

*/

public Integer getTopicId() {

return topicId;

}

/**

* @param topicId the topicId to set

*/

public void setTopicId(Integer topicId) {

this.topicId = topicId;

}

/**

* @return the topicName

*/

public String getTopicName() {

return topicName;

}

/**

* @param topicName the topicName to set

*/

public void setTopicName(String topicName) {

this.topicName = topicName;

}

/**

* @return the topicDesc

*/

public String getTopicDesc() {

return topicDesc;

}

/**

* @param topicDesc the topicDesc to set

*/

public void setTopicDesc(String topicDesc) {

this.topicDesc = topicDesc;

}

/**

* @return the createdAt

*/

public Date getCreatedAt() {

return createdAt;

}

/**

* @param createdAt the createdAt to set

*/

public void setCreatedAt(Date createdAt) {

this.createdAt = createdAt;

}

/**

* @return the userId

*/

public User getUserId() {

return userId;

}

/**

* @param userId the userId to set

*/

public void setUserId(User userId) {

this.userId = userId;

}

}

Spring Boot Class

@RestController

@RequestMapping("/qna/")

public class controller{

public ResponseEntity> postQuestion(@RequestBody Question){

}

}

Swagger-UI请求的对象

{

"title": "abc",

"topicList": []

}

预期的要求

{

"title": "abc",

"topicList": [

{

"topicName": "topic1",

"createdAt": ""

}

]

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值