flexjson.factories
Class DateObjectFactory

java.lang.Object
  extended by flexjson.factories.DateObjectFactory
All Implemented Interfaces:
ObjectFactory

public class DateObjectFactory
extends Object
implements ObjectFactory

DateObjectFactory instantiates java.lang.Date using a list of known java.text.DateFormat instances for json string types, or milliseconds from Jan 1, 1970 GMT for json numeric types. By default it uses the following patterns to recognize dates from json strings: DateFormat.getDateTimeInstance() DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG ) DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM ) DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT ) EEE MMM d hh:mm:ss a z yyyy EEE MMM d HH:mm:ss z yyyy MM/dd/yy hh:mm:ss a MM/dd/yy


Field Summary
protected  List<String> dateFormats
           
protected  ThreadLocal<List<DateFormat>> dateFormatters
           
protected  boolean fromDefaults
           
 
Constructor Summary
DateObjectFactory()
          This constructor constructs a DateObjectFactory using the default formats known to all instances of the DateObjectFactory.
DateObjectFactory(List<String> dateFormats)
          This constructs a DateObjectFactory that only knows how to recognize the given DateFormat instances.
 
Method Summary
 DateObjectFactory add(String... formats)
          Add a new DateFormat to the known formats this instance will recognise.
static void addDefaultFormat(String... formats)
          This method adds a default format for all DateObjectFactory.
protected  List<DateFormat> getDateFormats()
           
 Object instantiate(ObjectBinder context, Object value, Type targetType, Class targetClass)
          This is a method is used by Flexjson deserialization process to instantiate and bind all data into a Date instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dateFormats

protected List<String> dateFormats

fromDefaults

protected boolean fromDefaults

dateFormatters

protected ThreadLocal<List<DateFormat>> dateFormatters
Constructor Detail

DateObjectFactory

public DateObjectFactory()
This constructor constructs a DateObjectFactory using the default formats known to all instances of the DateObjectFactory.


DateObjectFactory

public DateObjectFactory(List<String> dateFormats)
This constructs a DateObjectFactory that only knows how to recognize the given DateFormat instances. This instance ignores any default formats. This can be used to as a way to optimize performance because it doesn't have to test each date against formats that will never occur in your program. This is great to use if you can predict all formats you might parse up front.

Parameters:
dateFormats - a list of the date formats you want to recognize.
Method Detail

addDefaultFormat

public static void addDefaultFormat(String... formats)
This method adds a default format for all DateObjectFactory. This can be used to add a new DateFormat to every instance created after this call.

Parameters:
formats - one or more date formats to add to the known default formats. All formats must conform to the SimpleDateFormat syntax.

add

public DateObjectFactory add(String... formats)
Add a new DateFormat to the known formats this instance will recognise.

Parameters:
formats - one or more DateFormat instances to add to the list of known formats.
Returns:
this instance for chaining calls.

instantiate

public Object instantiate(ObjectBinder context,
                          Object value,
                          Type targetType,
                          Class targetClass)
This is a method is used by Flexjson deserialization process to instantiate and bind all data into a Date instance. You shouldn't need to call this method directly.

Specified by:
instantiate in interface ObjectFactory
Parameters:
context - the object binding context to keep track of where we are in the object graph and used for binding into objects.
value - This is the value from the json object at the current path.
targetType - This is the type pulled from the object introspector. Used for Collections and generic types.
targetClass - concrete class pulled from the configuration of the deserializer.
Returns:
a properly initialized java.lang.Date object.

getDateFormats

protected List<DateFormat> getDateFormats()


Copyright © 2014. All Rights Reserved.