com.google.gdata.wireformats
Class ObjectConverter<T>

java.lang.Object
  extended by com.google.gdata.wireformats.ObjectConverter<T>
Type Parameters:
T - data type handled by this converter
Direct Known Subclasses:
ObjectConverter.MappedEnumConverter

public abstract class ObjectConverter<T>
extends java.lang.Object

Converts values from strings to typed values (objects).


Nested Class Summary
static class ObjectConverter.MappedEnumConverter<T>
          Object converter for pseudo-enum types backed by a map.
 
Constructor Summary
ObjectConverter()
           
 
Method Summary
static
<V> void
addConverter(java.lang.Class<V> type, ObjectConverter<V> converter)
          Add converter for a data type.
abstract  T convertValue(java.lang.String value, java.lang.Class<? extends T> datatype)
          Translate an untyped (string) value to a typed value.
static
<V> V
getValue(java.lang.Object value, java.lang.Class<V> datatype)
          Converts an object to the given datatype by casting if possible, and if not by narrowing from String using the registered object converters.
static
<V> V
getValue(java.lang.String value, java.lang.Class<V> datatype)
          Translate an untyped (string) value to a typed value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectConverter

public ObjectConverter()
Method Detail

addConverter

public static <V> void addConverter(java.lang.Class<V> type,
                                    ObjectConverter<V> converter)
Add converter for a data type.

Parameters:
type - data type
converter - converter

getValue

public static <V> V getValue(java.lang.Object value,
                             java.lang.Class<V> datatype)
                  throws ParseException
Converts an object to the given datatype by casting if possible, and if not by narrowing from String using the registered object converters.

Type Parameters:
V - the type of value to return.
Parameters:
value - the value to convert.
datatype - the datatype to convert to.
Returns:
the original value if it could be cast to the required type, or a narrowed version of the value if narrowing was possible.
Throws:
ParseException - if narrowing was not possible.

getValue

public static <V> V getValue(java.lang.String value,
                             java.lang.Class<V> datatype)
                  throws ParseException
Translate an untyped (string) value to a typed value.

Type Parameters:
V - data type
Parameters:
value - value
datatype - class of value type
Returns:
typed value
Throws:
ParseException - if value cannot be parsed according to type

convertValue

public abstract T convertValue(java.lang.String value,
                               java.lang.Class<? extends T> datatype)
                        throws ParseException
Translate an untyped (string) value to a typed value.

Parameters:
value - value to convert.
Returns:
value converted to type T.
Throws:
ParseException - if value cannot be parsed according to type