public abstract class

ObjectConverter

extends Object
java.lang.Object
   ↳ com.google.gdata.wireformats.ObjectConverter<T>
Known Direct Subclasses

Class Overview

Converts values from strings to typed values (objects).

Summary

Nested Classes
class ObjectConverter.MappedEnumConverter<T> Object converter for pseudo-enum types backed by a map. 
Fields
private static final ConcurrentMap<Class<?>, ObjectConverter<?>> CONVERTERS Map from data type to value convert.
Public Constructors
ObjectConverter()
Public Methods
static <V> void addConverter(Class<V> type, ObjectConverter<V> converter)
Add converter for a data type.
abstract T convertValue(String value, Class<? extends T> datatype)
Translate an untyped (string) value to a typed value.
static <V> V getValue(String value, Class<V> datatype)
Translate an untyped (string) value to a typed value.
static <V> V getValue(Object value, 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.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private static final ConcurrentMap<Class<?>, ObjectConverter<?>> CONVERTERS

Map from data type to value convert. This is used for types that don't have a string-arg constructor or need special handling.

Public Constructors

public ObjectConverter ()

Public Methods

public static void addConverter (Class<V> type, ObjectConverter<V> converter)

Add converter for a data type.

Parameters
type Data type
converter Converter

public abstract T convertValue (String value, Class<? extends T> datatype)

Translate an untyped (string) value to a typed value.

Parameters
value Value to convert.
datatype
Returns
  • value converted to type T.
Throws
ParseException if value cannot be parsed according to type

public static V getValue (String value, Class<V> datatype)

Translate an untyped (string) value to a typed value.

Parameters
value Value
datatype Class of value type
Returns
  • typed value
Throws
ParseException if value cannot be parsed according to type

public static V getValue (Object value, 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.

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.