package com.eactive.eai.rms.onl.manage.adapter.messagekey;

import java.util.List;

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.EMSRuntimeException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

@Component
public class StringToListMessageKeyUI implements Converter<String, List<MessageKeyUIField>> {

	private ObjectMapper objectMapper;

	@Autowired
	public StringToListMessageKeyUI(ObjectMapper objectMapper) {
		this.objectMapper = objectMapper;
	}

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