Short of writing my own function to do it, what is the easiest way to convert a TableRow
object, inside a dataflow 2.x pipeline, to a JSON-formatted String?
I thought the code below would work, but it isn't correctly inserting quotes in between key/values, especially where 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());
}
}
}
Use GSON
and do a gson.toJson(yourTableRow)
details here