英文:
ResultSet as ***String*** to Java POJO
问题
我有以下以字符串格式表示的ResultSet。出于与我的问题无关的原因,我只能将它作为一个字符串。如何从这个字符串创建一个Java POJO呢?
{
"columnNames": [
"cc.expiryDate",
"cc.number"
],
"values": [
[
1586131200000,
"3529-2930-4919-1213"
]
]
}
这是我的POJO类:
public class CreditCard {
private String number;
private Date expiryDate;
public Date getExpiryDate() {
return this.expiryDate;
}
public void setExpiryDate(Date expiryDate) {
this.expiryDate = expiryDate;
}
public String getNumber() {
return this.number;
}
public void setNumber(String number) {
this.number = number;
}
}
我知道如果我有一个ResultSet JDBC对象,我知道如果我有一个JSON columnName: value
语法,我该怎么做,但是我无法找到如何在拥有这个字符串的情况下做到这一点。我不想开发一个使用反射的算法 - 我可以做到这一点。我希望使用已经存在的库。我猜有两个选项:1) 解析字符串以创建一个ResultSet对象;2) 将字符串转换为JSON columnName: value
格式。有什么建议吗?
英文:
I have the following ResultSet in string format. For reasons not related to my question, I can only have it as a String. How can I create a Java POJO from this string?
{
"columnNames": [
"cc.expiryDate",
"cc.number"
],
"values": [
[
1586131200000,
"3529-2930-4919-1213"
]
]
}
Here is my POJO class:
public class CreditCard {
private String number;
private Date expiryDate;
public Date getExpiryDate() {
return this.expiryDate;
}
public void setExpiryDate(Date expiryDate) {
this.expiryDate = expiryDate;
}
public String getNumber() {
return this.number;
}
public void setNumber(String number) {
this.number = number;
}
}
I know how to do if I have a ResultSet JDBC object, I know how to do if I have a JSON columnName: value
syntax but I cannot find how to do it having this string. I am not looking for developing an algorithm that uses reflection - I could do this. I am looking for using already existing libraries. I guess two options are: 1) Parse the string to create a ResultSet object or 2) Convert the string to JSON colunmName: value
format. Any suggestions?
专注分享java语言的经验与见解,让所有开发者获益!
评论