For example, with Spark SQL
's data DataFrameReader
, you can invoke something like sqlContext.read().schema(customSchema).json(path)
where schema
function returns DataFrameReader
itself with the added configuration of customSchema
. Similarly, Jackson's ObjectWriter
has with
function which returns ObjectWriter
itself with some custom configuration passed through the with
function.
First, I am curious if this way of configuring through chaining method has it's own name, so that I can research further
Second, would this kind of method fit for a data format converter class where HTML, JSON, and CSV will be converted to one another? What I am imagining is having a static Converter
class that has from
and to
methods, where you specify the input and its dataformat type and the output and its dataformat type. So, it would look something like Converter.from("inputPath", DataFormat.CSV).to("outputPath", DataFormat.JSON")
and the blackbox should handle the process. The main reason I wanted to try this out is that, right now I have a method for each conversion, such as FromCSVToJSON
, but I didn't think it looks clean enough. Any alternative design suggestion for the Converter class is welcome.