com.sdl.dxa.tridion.mapping.converter.ListWrapperConverter Maven / Gradle / Ivy
package com.sdl.dxa.tridion.mapping.converter;
import com.sdl.dxa.api.datamodel.model.util.ListWrapper;
import com.sdl.dxa.tridion.mapping.ModelBuilderPipeline;
import com.sdl.dxa.tridion.mapping.impl.DefaultSemanticFieldDataProvider;
import com.sdl.webapp.common.api.mapping.semantic.config.SemanticField;
import com.sdl.webapp.tridion.fields.exceptions.FieldConverterException;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@Component
public class ListWrapperConverter implements SemanticModelConverter {
// can't be in a constructor because of circular dependency
@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@Autowired
private GenericSemanticModelDataConverter genericSemanticModelDataConverter;
@Override
public Object convert(ListWrapper toConvert, TypeInformation targetType, SemanticField semanticField, ModelBuilderPipeline pipeline,
DefaultSemanticFieldDataProvider dataProvider) throws FieldConverterException {
TypeDescriptor elementType = TypeDescriptor.valueOf(targetType.getObjectType());
if (targetType.isCollection()) {
Collection