es.prodevelop.pui9.data.converters.MapConverter Maven / Gradle / Ivy
package es.prodevelop.pui9.data.converters;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.springframework.core.convert.TypeDescriptor;
import es.prodevelop.pui9.json.GsonSingleton;
/**
* This class allows to set a @RequestParam parameter in your controllers
* indicating that the type of this parameter is a Map.
*
* @author Marc Gil - [email protected]
*/
public class MapConverter implements IPuiGenericConverter {
@Override
public Set getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(String.class, Map.class));
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
try {
Class> clazz = targetType.getType();
return GsonSingleton.getSingleton().getGson().fromJson(source.toString(), clazz);
} catch (Exception e) {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy