Example usage for org.springframework.data.util ClassTypeInformation MAP

List of usage examples for org.springframework.data.util ClassTypeInformation MAP

Introduction

In this page you can find the example usage for org.springframework.data.util ClassTypeInformation MAP.

Prototype

ClassTypeInformation MAP

To view the source code for org.springframework.data.util ClassTypeInformation MAP.

Click Source Link

Usage

From source file:io.twipple.springframework.data.clusterpoint.convert.DefaultClusterpointEntityConverter.java

/**
 * Convert a source object into a {@link ClusterpointDocument} target.
 *
 * @param source   the source object.//from  w  ww. j a  v a 2 s . c  o m
 * @param target   the target document.
 * @param typeHint the type information for the source.
 */
@SuppressWarnings("unchecked")
protected void writeInternal(final Object source, ClusterpointDocument target,
        final TypeInformation<?> typeHint) {
    if (source == null) {
        return;
    }

    Class<?> customTarget = conversions.getCustomWriteTarget(source.getClass(), ClusterpointDocument.class);
    if (customTarget != null) {
        copyClusterpointDocument(conversionService.convert(source, ClusterpointDocument.class), target);
        return;
    }

    if (Map.class.isAssignableFrom(source.getClass())) {
        writeMapInternal((Map<Object, Object>) source, target, ClassTypeInformation.MAP);
        return;
    }

    if (Collection.class.isAssignableFrom(source.getClass())) {
        throw new IllegalArgumentException("Root Document must be either CouchbaseDocument or Map.");
    }

    ClusterpointPersistentEntity<?> entity = mappingContext.getPersistentEntity(source.getClass());
    writeInternal(source, target, entity);
    addCustomTypeKeyIfNecessary(typeHint, source, target);
}

From source file:org.springframework.data.mongodb.core.convert.MappingMongoConverter.java

/**
 * Internal write conversion method which should be used for nested invocations.
 * /*from w  w  w  .  j  ava 2 s.  co  m*/
 * @param obj
 * @param dbo
 */
@SuppressWarnings("unchecked")
protected void writeInternal(final Object obj, final DBObject dbo, final TypeInformation<?> typeHint) {

    if (null == obj) {
        return;
    }

    Class<?> customTarget = conversions.getCustomWriteTarget(obj.getClass(), DBObject.class);

    if (customTarget != null) {
        DBObject result = conversionService.convert(obj, DBObject.class);
        dbo.putAll(result);
        return;
    }

    if (Map.class.isAssignableFrom(obj.getClass())) {
        writeMapInternal((Map<Object, Object>) obj, dbo, ClassTypeInformation.MAP);
        return;
    }

    if (Collection.class.isAssignableFrom(obj.getClass())) {
        writeCollectionInternal((Collection<?>) obj, ClassTypeInformation.LIST, (BasicDBList) dbo);
        return;
    }

    MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(obj.getClass());
    writeInternal(obj, dbo, entity);
    addCustomTypeKeyIfNecessary(typeHint, obj, dbo);
}