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

import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import com.eactive.eai.rms.onl.apim.approvalline.PortalApprovalLineUserUI;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

@Component
@RequiredArgsConstructor
public class StringToListPortalApprovalUserUIConverter implements Converter<String, List<PortalApprovalLineUserUI>> {

	private final ObjectMapper objectMapper;

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

}
