I have a Google Cloud Endpoint API which returns a Product
object. This product object itself contains another object Brand
which is very large (id, name, text, description, image URLs, ...). When getting a list of products I don't need the whole information inside Brand
, just the id and title.
So I tried to factor out Brand
to a base class BrandBase
which only contains a limited set of properties (only id and title). And inside Product
in the public BrandBase getBrand()
method I return a BrandBase
object.
But then looking at the JSON output from Google Cloud Endpoints - I still get the whole Brand
content (including all text, description, etc). So it looks like Google Cloud Endpoint just looks at the object-type and serializes everything regardless of the specified return type in the class itself?
@Entity
public class Product {
@Id
private Long id;
@Index
private Ref<BrandBase> brand;
public BrandBase getBrand() {
return brand.get();
}
public void setBrand(BrandBase brand) {
this.brand = Ref.create(brand);
}
...
}
@Entity
public class Brand extends BrandBase {
@Id
private Long id;
@Index
private String name;
private String text;
private String contact;
... all getter/setter ...
}
public abstract class BrandBase {
public abstract Long getId();
public abstract String getName();
public abstract void setName(String name);
}
the returned JSON is:
{
"id": "6298002603900928",
"title": "magna aliquyam erat, sed",
"description": "Lorem ipsum dolor sit amet...",
"brand": {
"id": "6192449487634432",
"name": "no",
"text": "Lorem ipsum dolor sit amet, ...",
"contact": "Lorem ipsum dolor..."
}
}
so it still contains text
and contact
- both are not specified in the BrandBase
class.
Is this a bug or feature of Google Cloud Endpoints? Or are there other methods to get my desired behavior: I only want to have a shallow brand object inside the product - not the full brand object.
@ApiTransformer
? – tx802