I have a entity relation in my application using the @Parent annotation to form entity groups.
https://code.google.com/p/objectify-appengine/wiki/Entities#@Parent_Relationships
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Parent;
@Entity
public class Person {
@Id Long id;
String name;
}
@Entity
public class Car {
@Parent Key<Person> owner;
@Id Long id;
String color;
}
I am using Google Cloud Endpoints to create a RESTFul service. I would like to create a GET in my resource that returns the JSON for not only the parent but for the entire entity group. What's a good way to do this?
What I have right now is this ...
@ApiMethod(
name = "persons.get",
httpMethod = HttpMethod.GET,
path = "persons/{id}"
)
public Person get(@Named("id") String webSafeKey) {
Key<Person> key = Key.create(webSafeKey);
Person person= ofy().load().key(key).safe();
return person;
}
This returns the JSON for person, but what if I want in to include the JSON for the person's cars. Maybe something like getters and setters getCars() in the person Object. I was wondering if there was something better though.
-- UPDATE --
Also, there doesn't seem to be a good way to return objects in the getters and setters that aren't literal nor convert to JSON without adapters.