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

public Class ToAttributedValueConverter

extends Object
implements Converter
Class Inheritance
All Implemented Interfaces
com.thoughtworks.xstream.converters.Converter, com.thoughtworks.xstream.converters.ConverterMatcher
Imports
java.lang.reflect.Field, .Modifier, java.util.HashMap, .HashSet, .Iterator, .Map, .Set, com.thoughtworks.xstream.converters.ConversionException, .Converter, .ConverterLookup, .ConverterMatcher, .MarshallingContext, .SingleValueConverter, .UnmarshallingContext, com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.DuplicateFieldException, .ReflectionProvider, com.thoughtworks.xstream.core.JVM, com.thoughtworks.xstream.core.util.FastField, .HierarchicalStreams, .Primitives, com.thoughtworks.xstream.io.HierarchicalStreamReader, .HierarchicalStreamWriter, com.thoughtworks.xstream.mapper.Mapper

Converter that supports the definition of one field member that will be written as value and all other field members are written as attributes. The converter requires that all the field types (expect the one with the value) are handled by a SingleValueConverter. The value field is defined using the name of the type that declares the field and the field name itself. Therefore it is possible to define an inherited field as value. It is also possible to provide no value field at all, so that all fields are written as attributes.
Author
Jörg Schaible
Since
1.4

Field Summary

Modifier and TypeField and Description
private final Mapper
private final ConverterLookup
private final Mapper
private final ReflectionProvider
private static final String
private final Class<T>
private final Field

Constructor Summary

AccessConstructor and Description
public
ToAttributedValueConverter(final Class<T>
the type that is handled by this converter instance
type
,
final Mapper
the mapper in use
mapper
,
final ReflectionProvider
the reflection provider in use
reflectionProvider
,
final ConverterLookup
the converter lookup in use
lookup
)

Creates a new ToAttributedValueConverter instance.

public
ToAttributedValueConverter(final Class<T>
the type that is handled by this converter instance
type
,
final Mapper
the mapper in use
mapper
,
final ReflectionProvider
the reflection provider in use
reflectionProvider
,
final ConverterLookup
the converter lookup in use
lookup
,
final String
the field defining the tag's value (may be null)
valueFieldName
)

Creates a new ToAttributedValueConverter instance.

public
ToAttributedValueConverter(final Class<T>
the type that is handled by this converter instance
type
,
final Mapper
the mapper in use
mapper
,
final ReflectionProvider
the reflection provider in use
reflectionProvider
,
final ConverterLookup
the converter lookup in use
lookup
,
final String
the field defining the tag's value (may be null)
valueFieldName
,
Class<T>
the type defining the field
valueDefinedIn
)

Creates a new ToAttributedValueConverter instance.

Method Summary

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

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

Determines whether the converter can marshall a particular type.
private boolean
public void
marshal(final Object
The object to be marshalled.
source
,
final HierarchicalStreamWriter
A stream to write to.
writer
,
final MarshallingContext
A context that allows nested objects to be processed by XStream.
context
)

Implements com.thoughtworks.xstream.converters.Converter.marshal.

Convert an object to textual data.
public Object
unmarshal(final HierarchicalStreamReader
The stream to read the text from.
reader
,
final UnmarshallingContext context)

Implements com.thoughtworks.xstream.converters.Converter.unmarshal.

Convert textual data back into an object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

enumMapperback to summary
private final Mapper enumMapper
lookupback to summary
private final ConverterLookup lookup
mapperback to summary
private final Mapper mapper
reflectionProviderback to summary
private final ReflectionProvider reflectionProvider
STRUCTURE_MARKERback to summary
private static final String STRUCTURE_MARKER
typeback to summary
private final Class<T> type
valueFieldback to summary
private final Field valueField

Constructor Detail

ToAttributedValueConverterback to summary
public ToAttributedValueConverter(final Class<T> type, final Mapper mapper, final ReflectionProvider reflectionProvider, final ConverterLookup lookup)

Creates a new ToAttributedValueConverter instance. All field elements will be attributes, the element itself will have no value.

Parameters
type:Class<T>

the type that is handled by this converter instance

mapper:Mapper

the mapper in use

reflectionProvider:ReflectionProvider

the reflection provider in use

lookup:ConverterLookup

the converter lookup in use

Since
1.4.9
ToAttributedValueConverterback to summary
public ToAttributedValueConverter(final Class<T> type, final Mapper mapper, final ReflectionProvider reflectionProvider, final ConverterLookup lookup, final String valueFieldName)

Creates a new ToAttributedValueConverter instance.

Parameters
type:Class<T>

the type that is handled by this converter instance

mapper:Mapper

the mapper in use

reflectionProvider:ReflectionProvider

the reflection provider in use

lookup:ConverterLookup

the converter lookup in use

valueFieldName:String

the field defining the tag's value (may be null)

ToAttributedValueConverterback to summary
public ToAttributedValueConverter(final Class<T> type, final Mapper mapper, final ReflectionProvider reflectionProvider, final ConverterLookup lookup, final String valueFieldName, Class<T> valueDefinedIn)

Creates a new ToAttributedValueConverter instance.

Parameters
type:Class<T>

the type that is handled by this converter instance

mapper:Mapper

the mapper in use

reflectionProvider:ReflectionProvider

the reflection provider in use

lookup:ConverterLookup

the converter lookup in use

valueFieldName:String

the field defining the tag's value (may be null)

valueDefinedIn:Class<T>

the type defining the field

Method Detail

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

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

fieldIsEqualback to summary
private boolean fieldIsEqual(FastField field)
marshalback to summary
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context)

Implements com.thoughtworks.xstream.converters.Converter.marshal.

Doc from com.thoughtworks.xstream.converters.Converter.marshal.

Convert an object to textual data.

Parameters
source:Object

The object to be marshalled.

writer:HierarchicalStreamWriter

A stream to write to.

context:MarshallingContext

A context that allows nested objects to be processed by XStream.

unmarshalback to summary
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context)

Implements com.thoughtworks.xstream.converters.Converter.unmarshal.

Doc from com.thoughtworks.xstream.converters.Converter.unmarshal.

Convert textual data back into an object.

Parameters
reader:HierarchicalStreamReader

The stream to read the text from.

Returns:Object

The resulting object.