[
https://issues.apache.org/jira/browse/CAMEL-13578?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen resolved CAMEL-13578.
---------------------------------
Resolution: Won't Fix
Lets keep it as is
> Implementation of List and Map utilising TypeConverter
> ------------------------------------------------------
>
> Key: CAMEL-13578
> URL: https://issues.apache.org/jira/browse/CAMEL-13578
> Project: Camel
> Issue Type: New Feature
> Components: camel-core
> Affects Versions: 3.0.0-M2
> Reporter: Jan Bednar
> Priority: Minor
>
> We have implemented this in our project. This is convenient for working with
> List<Map<>> and Map<List<>>objects.
> I can implement this into Camel, but there is massive refactoring in Camel 3
> about modules and I`m not quite sure if this should be part of core, support,
> base,... , or event special new module. Any thoughts or docs about camel 3
> module architecture?
> *Usage:*
> {code:java}
> //Body contains List<Map<String, String>>
> String.value = exchange.getIn()
> .getBody(TypeConverterList.class)
> .get(0, TypeConverterMap.class)
> .get("key1", String.class);{code}
> which is more flexible alternative to current approach
> {code:java}
> String value =
> (String)(((Map)exchange.getIn().getBody(List.class).get(0)).get("key1"));{code}
>
> This is achieved implementing two new TypeConverters: *List ->
> TypeConverterList* and *Map -> TypeConverterMap*.
> Instances of *TypeConverterList* and *TypeConverterMap* holds reference to
> org.apache.camel.TypeConverter
> and looks like:
>
> {code:java}
> public class TypeConverterMap<K,V> extends ForwardingMap<K,V> {
> private final TypeConverter typeConverter;
> private final Map<K,V> delegate;
> public TypeConverterMap(CamelContext camelContext, Map<K,V> delegate) {
> this.delegate = delegate;
> this.typeConverter = camelContext.getTypeConverter();
> }
> @Override
> protected Map<K,V> delegate() {
> return delegate;
> }
> public <T> T get(K key, Class<T> clazz){
> return typeConverter.convertTo(clazz, get(key));
> }
> public <T extends V> T getOrDefault(K key, V defaultValue, Class<T>
> clazz) {
> return typeConverter.convertTo(clazz, getOrDefault(key,
> defaultValue));
> }
> }{code}
>
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)