Google Cloud Dataflowを探索しています。JavaオブジェクトをBigQuery TableRowに変換する
JavaオブジェクトまたはJSONとTableRowの間の自動変換ができるかどうかは疑問でした。
JSONとPOJOクラスを自動的に解析できるようにします。
関連情報が見つかりませんでした。 質問は重複しないことを願っています。
情報に感謝します!
ごあいさつ
Google Cloud Dataflowを探索しています。JavaオブジェクトをBigQuery TableRowに変換する
JavaオブジェクトまたはJSONとTableRowの間の自動変換ができるかどうかは疑問でした。
JSONとPOJOクラスを自動的に解析できるようにします。
関連情報が見つかりませんでした。 質問は重複しないことを願っています。
情報に感謝します!
ごあいさつ
私は同じ運がない場合の例を探しています。私はbigqueryテーブルのスキーマとほぼ一致するPOJOクラスを作成し、パイプラインの入力であるJSONオブジェクトの構造と一致させました。最後に、私が持っているとき、私は以下のようなものを作っ入れ子になったし、繰り返される値のために、のTableRowにこれらのオブジェクトを変換すると、変換がAPIによって作られた
Itemクラスは、Orderオブジェクトの一部であるTableRow row = new TableRow()
.set("items", c.element().getItems())
.set("orderDate", c.element().getOrderDate())
.set("orderNumber", c.element().getOrderNumber());
:
@JsonProperty("items")
private List<Item> items = null;
これは、Itemクラスのコードです:
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);
}
}
そして、これは、項目がRECORDと繰り返しフィールドであり、またcontaiについての項目でBigQueryのテーブルのスキーマであり、 nネストされたRECORDおよびREPEATEDフィールド:製品。スキーマのスクリーンショットを参照してください。