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

import com.eactive.eai.rms.onl.apim.apigroup.ui.ApiGroupApiUI;
import com.eactive.eai.rms.onl.apim.apigroup.ui.ApiGroupUI;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class StringToListApiGroupUIConverter implements Converter<String, List<ApiGroupUI>> {

	private final ObjectMapper objectMapper;

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

}
