Class JsonArrayToCSV
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.transform.csvjson.CSVConverter
-
- com.adaptris.core.transform.csvjson.JsonArrayToCSV
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,Service
,StateManagedComponent
- Direct Known Subclasses:
JsonToFixedCSV
@ComponentProfile(summary="Transfrom a JSON Array/JSON Lines document into a CSV", tag="service,csv,json") public class JsonArrayToCSV extends CSVConverter
Transfrom a JSON array into a CSV.Takes a JSON array and renders it as a CSV document:
[ { "firstname":"alice", "lastname":"smith", "dob":"2017-01-01" }, { "firstname":"bob", "lastname":"smith", "dob":"2017-01-02" }, { "firstname":"carol", "lastname":"smith", "dob":"2017-01-03" } ]
firstname, lastname, dob "alice","smith", "2017-01-01" "bob", "smith", "2017-01-02" "carol","smith", "2017-01-03"
nested JSON objects will be rendered as strings before being passed into the appropriate statement; so
{ "firstname":"alice", "lastname":"smith", "address": { "address" : "Buckingham Palace", "postcode":"SW1A 1AA"}}
still only be 3 CSV columns the address column will be"{ "address" : "Buckingham Palace", "postcode":"SW1A 1AA"}"
In the adapter configuration file this class is aliased as json-to-csv which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description JsonArrayToCSV()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doService(AdaptrisMessage msg)
java.lang.String
getIncludeHeader()
Whether or not to emit a header line.JsonProvider.JsonStyle
getJsonStyle()
Specify how the payload is parsed to provide JSON objects.protected boolean
includeHeader(AdaptrisMessage msg)
protected JsonProvider.JsonObjectProvider
jsonStyle()
void
setIncludeHeader(java.lang.String includeHeader)
Whether or not to emit a header line.void
setJsonStyle(JsonProvider.JsonStyle jsonStyle)
Specify how the payload is parsed to provide JSON objects.<T extends JsonArrayToCSV>
TwithIncludeHeader(java.lang.String s)
<T extends JsonArrayToCSV>
TwithJsonStyle(JsonProvider.JsonStyle p)
-
Methods inherited from class com.adaptris.core.transform.csvjson.CSVConverter
closeService, getPreferenceBuilder, initService, prepare, setPreferenceBuilder, withPreferenceBuilder
-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
- Throws:
ServiceException
-
includeHeader
protected boolean includeHeader(AdaptrisMessage msg)
-
jsonStyle
protected JsonProvider.JsonObjectProvider jsonStyle()
-
withJsonStyle
public <T extends JsonArrayToCSV> T withJsonStyle(JsonProvider.JsonStyle p)
-
withIncludeHeader
public <T extends JsonArrayToCSV> T withIncludeHeader(java.lang.String s)
-
getIncludeHeader
public java.lang.String getIncludeHeader()
Whether or not to emit a header line.
-
setIncludeHeader
public void setIncludeHeader(java.lang.String includeHeader)
Whether or not to emit a header line.
-
getJsonStyle
public JsonProvider.JsonStyle getJsonStyle()
Specify how the payload is parsed to provide JSON objects.The default if not specified is a
JSON_ARRAY
-
setJsonStyle
public void setJsonStyle(JsonProvider.JsonStyle jsonStyle)
Specify how the payload is parsed to provide JSON objects.The default if not specified is a
JSON_ARRAY
-
-