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

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

import java.util.List;

@Component
@RequiredArgsConstructor
public class StringToListApiGroupApiUIConverter implements Converter<String, List<ApiGroupApiUI>> {

	private final ObjectMapper objectMapper;

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

}
