com.googlecode.objectify.impl.conv.ArrayConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectify Show documentation
Show all versions of objectify Show documentation
*** THIS VERSION UPLOADED FOR USE WITH CEDAR-COMMON, TO AVOID DEPENDENCIES ON GOOGLE CODE-BASED MAVEN REPOSITORIES. *** The simplest convenient interface to the Google App Engine datastore
The newest version!
package com.googlecode.objectify.impl.conv;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import com.google.appengine.api.datastore.Blob;
/**
* Knows how to convert java arrays. Note that each individual element must be
* converted as well.
*/
public class ArrayConverter implements Converter
{
/** Need this to convert members */
Conversions conversions;
/** */
public ArrayConverter(Conversions conv)
{
this.conversions = conv;
}
@Override
public Object forDatastore(Object value, ConverterSaveContext ctx)
{
if (!value.getClass().isArray())
return null;
if (ctx.inEmbeddedCollection())
throw new IllegalStateException("You cannot have arrays within @Embedded arrays or collections");
if (value.getClass().getComponentType() == Byte.TYPE)
{
// Special case! byte[] gets turned into Blob.
return new Blob((byte[])value);
}
else
{
// The datastore cannot persist arrays, but it can persist ArrayList
int length = Array.getLength(value);
ArrayList