英文:
REST API JSON response in POSTMAN: one field is coming as null in response
问题
在使用JPA将实体保存到DERBY DB时,当我发布JSON并尝试将数据保存到数据库时,响应中的url字段为空,而数据插入正常进行,我没有收到任何错误。
POJO类:
@Entity
public class Message {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String title;
private String content;
private String sender;
private String URL;
public Message(){
}
public Message(String URL, Long id, String title, String content, String sender) {
super();
this.URL = URL;
this.id = id;
this.title = title;
this.content = content;
this.sender = sender;
}
public String getURL() {
return URL;
}
public void setURL(String uRL) {
URL = uRL;
}
@JsonIgnore
@JsonProperty(value = "id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
}
发布的JSON:
{
"title": "alpha beta gama",
"content": "greek letters" ,
"sender": "laura",
"URL": "http://abc.efg"
}
响应:
{
"title": "alpha beta gama",
"content": "greek letters",
"sender": "laura",
"url": null
}
英文:
I am saving this entity using JPA in DERBY DB, whenever I am posting JSON and trying to save data in DB, my url field is coming null in response, while insertion of data is going well and I am not getting any error.
POJO class:
@Entity
public class Message {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String title;
private String content;
private String sender;
private String URL;
public Message(){
}
public Message(String URL,Long id ,String title, String content, String sender) {
super();
this.URL = URL;
this.id = id;
this.title = title;
this.content = content;
this.sender = sender;
}
public String getURL() {
return URL;
}
public void setURL(String uRL) {
URL = uRL;
}
@JsonIgnore
@JsonProperty(value = "id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
}
post JSON:
{
"title":"alpha beta gama",
"content":"greek letters" ,
"sender":"laura",
"URL":"http://abc.efg"
}
Response
{
"title": "alpha beta gama",
"content": "greek letters",
"sender": "laura",
"url": null
}
答案1
得分: 1
你尝试使用小写的 "url" 而不是 "URL" 吗?
英文:
Did you try to user lowercase "url" instead of "URL"?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论