1
我正在探索Google Cloud Dataflow。將Java對象轉換爲BigQuery TableRow
我想知道如果Java對象或JSON自動轉換爲TableRow是否可以完成。
就像我們可以自動分析JSON到POJO類一樣。
我找不到相關信息。 希望不要重複的問題。
將不勝感激的任何信息!
問候
我正在探索Google Cloud Dataflow。將Java對象轉換爲BigQuery TableRow
我想知道如果Java對象或JSON自動轉換爲TableRow是否可以完成。
就像我們可以自動分析JSON到POJO類一樣。
我找不到相關信息。 希望不要重複的問題。
將不勝感激的任何信息!
問候
我找同樣的例子沒有運氣。我創建了一個POJO類,它幾乎與bigquery表的模式匹配,並匹配作爲管道輸入的JSON對象的結構。最後,當我對這些對象轉換爲tablerow,爲我做了類似下面的嵌套和重複值,和轉換是由API的
TableRow row = new TableRow()
.set("items", c.element().getItems())
.set("orderDate", c.element().getOrderDate())
.set("orderNumber", c.element().getOrderNumber());
其中Item類是訂單對象的一部分:
@JsonProperty("items")
private List<Item> items = null;
這是項目類的代碼:
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"id",
"code",
"detail",
"name",
"shortName",
"description",
"sku",
"quantity",
"category",
"products"
})
public class Item implements Serializable
{
@JsonProperty("id")
private Integer id;
@JsonProperty("code")
private String code;
@JsonProperty("detail")
private String detail;
@JsonProperty("name")
private String name;
@JsonProperty("shortName")
private String shortName;
@JsonProperty("description")
private String description;
@JsonProperty("sku")
private String sku;
@JsonProperty("quantity")
private Integer quantity;
@JsonProperty("category")
private Category category;
@JsonProperty("products")
private List<Product> products = null;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private final static long serialVersionUID = -5644586446669059821L;
@JsonProperty("id")
public Integer getId() {
return id;
}
@JsonProperty("id")
public void setId(Integer id) {
this.id = id;
}
@JsonProperty("code")
public String getCode() {
return code;
}
@JsonProperty("code")
public void setCode(String code) {
this.code = code;
}
@JsonProperty("detail")
public String getDetail() {
return detail;
}
@JsonProperty("detail")
public void setDetail(String detail) {
this.detail = detail;
}
@JsonProperty("name")
public String getName() {
return name;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("shortName")
public String getShortName() {
return shortName;
}
@JsonProperty("shortName")
public void setShortName(String shortName) {
this.shortName = shortName;
}
@JsonProperty("description")
public String getDescription() {
return description;
}
@JsonProperty("description")
public void setDescription(String description) {
this.description = description;
}
@JsonProperty("sku")
public String getSku() {
return sku;
}
@JsonProperty("sku")
public void setSku(String sku) {
this.sku = sku;
}
@JsonProperty("quantity")
public Integer getQuantity() {
return quantity;
}
@JsonProperty("quantity")
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
@JsonProperty("category")
public Category getCategory() {
return category;
}
@JsonProperty("category")
public void setCategory(Category category) {
this.category = category;
}
@JsonProperty("products")
public List<Product> getProducts() {
return products;
}
@JsonProperty("products")
public void setProducts(List<Product> products) {
this.products = products;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
這是BigQuery資料表中關於項目的模式,其中項目是一個記錄和重複欄還包含3 n嵌套的RECORD和REPEATED字段:產品。請參閱架構屏幕截圖