Unfortunately no, java.net.URL is not a natively supported property
type. However it's pretty easy to make Objectify automatically
convert it to String. I just added this to Objectify4 if you're
comfortable building from trunk (and upgrading - the API has changed
quite significantly).
In Objectify3, add this converter to your ObjectifyFactory:
/**
* Call factory.getConversions().add(new URLConverter());
*/
public class URLConverter implements Converter
{
@Override
public Object forDatastore(Object value, ConverterSaveContext ctx)
{
if (value instanceof URL)
return ((URL) value).toString()();
else
return null;
}
@Override
public Object forPojo(Object value, Class<?> fieldType,
ConverterLoadContext ctx, Object onPojo)
{
if (value instanceof String &&
URL.class.isAssignableFrom(fieldType))
return new URL((String)value); // you'll need
to try/catch the MalformedURLException here
else
return null;
}
}
Jeff
On Wed, Jan 25, 2012 at 11:22 AM, Christopher Johnson
<[email protected]> wrote:
> All -
>
> I had question about supported property types for Java, I'm working
> with GAE and Objectify and one of my embedded objects has a
> java.net.URL member, when trying to store the object I get the
> following error:
>
> java.lang.IllegalArgumentException java.net.URL is not a supported
> property type.
>
> public ObjectA{
> @Unindexed @Embedded private ObjectB objb;
> // getters and setters
> }
>
> public ObjectB {
> private URL url;
> // getters and setter
> }
>
> In my DAO I do something like ofy().put(obja) and out comes the
> error ? I'm clearly missing something simple here, just can't put my
> finger on it, can anyone throw out some quick help ?
>
> Thanks,
> ..Chris
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.