我需要将String
这种格式的 s 转换成一个Array
对象。
[{name=Nancy Chapman, email=nchapman0@comcast.net}, {name=Jimmy Fisher, email=jfisher1@photobucket.com}]
有什么简单的方法可以转换它而无需完全手动完成?
更新:我从自定义 SQL 数据库 (Amazon Athena) 中提取这些值。而且自定义JDBC
不支持getArray()
,所以看起来我需要手动解析包含Array
of的列Structs
。不幸的是,这是数据库的限制,我无法控制它。getString()
这是我在列上调用时 SQL 数据库返回的格式。
SQL 表定义
id (int)
threadid (int)
senderemail (string)
sendername (string)
subject (string)
body (string)
recipients (array<struct<name:string,email:string>>)
ccrecipients (array<struct<name:string,email:string>>)
bccrecipients (array<struct<name:string,email:string>>)
attachments (array<binary>)
date (timestamp)
Java 对象
MessageObj
public class MessageObj {
private int id;
private int threadId;
private String senderEmail;
private String senderName;
private String subject;
private String body;
private List<RecipientObj> recipients;
private List<RecipientObj> ccRecipients;
private List<RecipientObj> bccRecipients;
private List<File> attachments;
private Calendar date;
}
RecipientObj
public class RecipientObj {
private String email;
private String name;
}
解析数据。
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
// Retrieve table column.
int id = rs.getInt("id");
Integer threadId = rs.getInt("threadid");
String senderEmail = rs.getString("senderemail");
String senderName = rs.getString("sendername");
String subject = rs.getString("subject");
String body = rs.getString("body");
//How to convert recipients into ArrayList? rs.getArray("recipients") not supported.
//... Code here to add into an ArrayList of MessageObj.
}