Java – in dataflow 2 X is the easiest way to convert a tablerow to a string in JSON format?

If I don't write my own function to complete it, then in data stream 2 What is the easiest way to convert a tablerow object into a JSON formatted string in the X pipeline?

I think the following code works, but it doesn't insert quotes correctly between keys / values, especially if there are nested fields

public static class TableRowToString extends DoFn<TableRow,String> {    
  private static final long serialVersionUID = 1L;

  @ProcessElement
    public void processElement(ProcessContext c) {
      c.output(c.element().toString());
    }
  }
}

Solution

Use gson and execute gson Tojason (yourtablerow) details here

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>