public class ErpTypeSerializer extends Object
Constructor and Description |
---|
ErpTypeSerializer()
Initializes the
ErpTypeSerializer with default ERP type converters. |
Modifier and Type | Method and Description |
---|---|
<T> ConvertedObject<T> |
fromErp(String erpObject,
Class<T> resultType)
Convert a given String based erpObject in the ERP-based representation into an object of resultType.
|
Collection<ErpTypeConverter<?>> |
getTypeConverters()
Gets registered
ErpTypeConverter s. |
Map<Class<?>,ErpTypeConverter<?>> |
getTypeConvertersByType()
Gets registered
ErpTypeConverter s for each ErpType . |
<T> ConvertedObject<String> |
toErp(T object)
Convert given object to an ERP type using a registered
ErpTypeConverter . |
ErpTypeSerializer |
withTypeConverters(ErpTypeConverter<?>... typeConverters)
Delegates to
withTypeConverters(Iterable) . |
ErpTypeSerializer |
withTypeConverters(Iterable<ErpTypeConverter<?>> typeConverters)
Registers the given
ErpTypeConverter s. |
public ErpTypeSerializer()
ErpTypeSerializer
with default ERP type converters.@Nonnull public ErpTypeSerializer withTypeConverters(Iterable<ErpTypeConverter<?>> typeConverters)
ErpTypeConverter
s. Replaces existing converters for already existing types that have
been added before.@Nonnull public ErpTypeSerializer withTypeConverters(ErpTypeConverter<?>... typeConverters)
withTypeConverters(Iterable)
.@Nonnull public Collection<ErpTypeConverter<?>> getTypeConverters()
ErpTypeConverter
s.@Nonnull public Map<Class<?>,ErpTypeConverter<?>> getTypeConvertersByType()
ErpTypeConverter
s for each ErpType
.@Nonnull public <T> ConvertedObject<String> toErp(@Nullable T object)
ErpTypeConverter
.
Example usage in the SDK ErpTypeSerializer
test:
final ErpTypeSerializer serializer = new ErpTypeSerializer(); assertThat(serializer.toErp(new CostCenter("123")).get()).isEqualTo("0000000123"); assertThat(serializer.toErp(-123.4d).get()).isEqualTo("123.4-");
@Nonnull public <T> ConvertedObject<T> fromErp(@Nullable String erpObject, Class<T> resultType)
ErpTypeConverter
registered for resultType.
* Example usage in the SDK ErpTypeSerializer
test:
assertThat(serializer.fromErp("0000000123", CostCenter.class).get()).isEqualTo(new CostCenter("123")); assertThat(serializer.fromErp("123.4 ", Double.class).get()).isEqualTo(123.4d); assertThat(serializer.fromErp("123.4-", Double.class).get()).isEqualTo(-123.4d);
Copyright © 2019 SAP SE. All rights reserved.