Example usage for org.springframework.core.convert TypeDescriptor isPrimitive

List of usage examples for org.springframework.core.convert TypeDescriptor isPrimitive

Introduction

In this page you can find the example usage for org.springframework.core.convert TypeDescriptor isPrimitive.

Prototype

public boolean isPrimitive() 

Source Link

Document

Is this type a primitive type?

Usage

From source file:org.springframework.core.convert.support.GenericConversionService.java

/**
 * Template method to convert a null source.
 * <p>Default implementation returns <code>null</code>.
 * Throws a {@link ConversionFailedException} if the targetType is a primitive type,
 * as <code>null</code> cannot be assigned to a primitive type.
 * Subclasses may override to return custom null objects for specific target types.
 * @param sourceType the sourceType to convert from
 * @param targetType the targetType to convert to
 * @return the converted null object// w w w . j  a v a  2 s .co  m
 */
protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) {
    if (targetType.isPrimitive()) {
        throw new ConversionFailedException(sourceType, targetType, null,
                new IllegalArgumentException("A null value cannot be assigned to a primitive type"));
    }
    return null;
}