Top Description Fields Constructors Methods
com.thoughtworks.xstream.converters.extended

public Class SqlTimestampConverter

extends AbstractSingleValueConverter
Class Inheritance
Imports
com.thoughtworks.xstream.converters.ConversionException, com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter, com.thoughtworks.xstream.core.util.ThreadSafeSimpleDateFormat, java.sql.Timestamp, java.text.ParseException, java.util.TimeZone

Converts a Timestamp to a string.
Authors
Joe Walnes, Jörg Schaible

Field Summary

Modifier and TypeField and Description
private final ThreadSafeSimpleDateFormat

Constructor Summary

AccessConstructor and Description
public
SqlTimestampConverter()

Constructs a SqlTimestampConverter using UTC format.

public
SqlTimestampConverter(final TimeZone
the time zone used for the format
timeZone
)

Constructs a SqlTimestampConverter.

Method Summary

Modifier and TypeMethod and Description
public boolean
canConvert(Class<T>
the Class representing the object type to be converted
type
)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.canConvert.

Implements com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Determines whether the converter can marshall a particular type.
public Object
fromString(final String
the String with the single value of the Object
str
)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.fromString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Unmarshals an Object from its single value representation.
public String
toString(final Object
the Object to be converted
obj
)

Overrides com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.toString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.toString.

Marshals an Object into a single value representation.

Field Detail

formatback to summary
private final ThreadSafeSimpleDateFormat format

Constructor Detail

SqlTimestampConverterback to summary
public SqlTimestampConverter()

Constructs a SqlTimestampConverter using UTC format.

SqlTimestampConverterback to summary
public SqlTimestampConverter(final TimeZone timeZone)

Constructs a SqlTimestampConverter.

XStream uses by default UTC as time zone. However, if the resulting XML is used as feed for a data base (like MS SQL) the server might expect the timestamp to be in local time and does the conversion to UTC on its own. In such a case you can register an own instance of the SqlTimestamp converter using e.g. TimeZone#getDefault().

Parameters
timeZone:TimeZone

the time zone used for the format

Since
1.4.10

Method Detail

canConvertback to summary
public boolean canConvert(Class<T> type)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.canConvert.

Implements com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Doc from com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Determines whether the converter can marshall a particular type.

Parameters
type:Class<T>

the Class representing the object type to be converted

fromStringback to summary
public Object fromString(final String str)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.fromString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Doc from com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Unmarshals an Object from its single value representation.

Parameters
str:String

the String with the single value of the Object

Returns:Object

the Object

toStringback to summary
public String toString(final Object obj)

Overrides com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.toString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.toString.

Doc from com.thoughtworks.xstream.converters.SingleValueConverter.toString.

Marshals an Object into a single value representation.

Parameters
obj:Object

the Object to be converted

Returns:String

a String with the single value of the Object or null