org.modelmapper.jackson.CollectionToArrayNodeConverter Maven / Gradle / Ivy
package org.modelmapper.jackson;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.MissingNode;
import org.modelmapper.internal.Errors;
import org.modelmapper.spi.ConditionalConverter;
import org.modelmapper.spi.MappingContext;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
/**
* Converts {@link ArrayNode} instances to {@link Collection} instances.
*
* @author Chun Han Hsiao
*/
public class CollectionToArrayNodeConverter implements ConditionalConverter, ArrayNode> {
private ObjectMapper objectMapper;
public CollectionToArrayNodeConverter(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
@Override
public MatchResult match(Class> sourceType, Class> destinationType) {
return Collection.class.isAssignableFrom(sourceType) && ArrayNode.class.isAssignableFrom(destinationType)
? MatchResult.FULL : MatchResult.NONE;
}
@Override
public ArrayNode convert(MappingContext, ArrayNode> context) {
Collection