package com.eactive.eai.rms.common.converter;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import com.eactive.eai.rms.onl.common.exception.BizException;
import com.eactive.eai.rms.onl.manage.adapter.adapter.ui.AdapterUI;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

@Component
public class StringToMapAdapterUIConverter implements Converter<String, Map<String, AdapterUI>> {
	@Autowired
	private ObjectMapper objectMapper;

	@Override
	public Map<String, AdapterUI> convert(String source) {
		try {
			return objectMapper.readValue(source, new TypeReference<Map<String, AdapterUI>>() {
			});
		} catch (JsonProcessingException e) {
			throw new BizException(e);
		}
	}
}
