Class ISOStringDateTransformer

java.lang.Object
com.invirgance.convirgance.transform.date.ISOStringDateTransformer
All Implemented Interfaces:
IdentityTransformer, Transformer

@Wiring public class ISOStringDateTransformer extends Object implements IdentityTransformer
Transforms ISO 8601 formatted strings into Date objects.

Example usage:

 Iterable<JSONObject> stream = ...;
 
 // Convert specified fields
 StringDateTransformer transformer = new StringDateTransformer("created_at", "updated_at");

 // Apply the transformation
 stream = transformer.transform(stream);
 
Author:
jbanes
  • Constructor Details

    • ISOStringDateTransformer

      public ISOStringDateTransformer()
      Prepares a new transformer to parse ISO 8601 strings into Date objects. You must call setColumns(java.lang.String...) before attempting a transform or an exception will be thrown.
    • ISOStringDateTransformer

      public ISOStringDateTransformer(String... columns)
      Creates a new transformer that parses ISO 8601 strings into Date objects
      Parameters:
      columns - field names to include in the conversion
  • Method Details

    • getColumns

      public String[] getColumns()
      Get the list of columns that will be transformed. Null is returned if no column list has been set. In this case, all columns will be checked.
      Returns:
      list of columns to be converted or null if all columns will be checked
    • setColumns

      public void setColumns(String... columns)
      Set the list of columns to transform. Null may be passed if all columns should be checked and transformed if they are of type Date.
      Parameters:
      columns - list of columns to be converted
    • transform

      public JSONObject transform(JSONObject record) throws ConvirganceException
      Description copied from interface: IdentityTransformer
      Transforms the provided record in some way.
      Specified by:
      transform in interface IdentityTransformer
      Parameters:
      record - The JSONObject to transform/modify.
      Returns:
      The modified JSONObject.
      Throws:
      ConvirganceException - If an error occurs while making transformations.