diff options
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/com')
-rw-r--r-- | id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java index da2c4b7e6..7a52d0c9d 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java @@ -1,6 +1,7 @@ package com.datentechnik.moa.id.conf.persistence; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Required; @@ -8,13 +9,16 @@ import org.springframework.stereotype.Component; import com.datentechnik.moa.id.conf.persistence.dal.ConfigProperty; import com.datentechnik.moa.id.conf.persistence.dal.ConfigPropertyDao; -import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.databind.type.TypeFactory; /** * @@ -89,12 +93,26 @@ public class ConfigurationImpl implements Configuration { } } + @SuppressWarnings("unchecked") @Override public <T> List<T> getList(String key, Class<T> clazz) { - // return empty list if key does not exist - // TODO Auto-generated method stub - return null; + CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(List.class, clazz); + String json = configPropertyDao.getProperty(key).getValue(); + ObjectMapper mapper = new ObjectMapper(); + + try { + return (List<T>) mapper.readValue(json, listType); + } catch (JsonMappingException e) { + ArrayList<T> tmp = new ArrayList<T>(); + T value = get(key, clazz); + if(value != null){ + tmp.add(value); + } + return tmp; + } catch (IOException e) { + return new ArrayList<T>(); + } } private String getPropertyValue(String key) { @@ -150,7 +168,8 @@ public class ConfigurationImpl implements Configuration { ObjectMapper mapper = new ObjectMapper(); if (clazz != null) { - return mapper.readValue(value, clazz); + JavaType javaType = TypeFactory.defaultInstance().constructType(clazz); + return mapper.readValue(value, javaType); } else { return mapper.readValue(value, Object.class); } |