[google-endpoint-v2] rename entity prior to serialization

91 views
Skip to first unread message

Raunak Gupta

unread,
Jul 3, 2017, 6:03:42 PM7/3/17
to Google App Engine
How can you rename an entity before returning the response. I tried using @Jsonproperty("label") on the getter method, but didn't yield any result. 

George (Cloud Platform Support)

unread,
Jul 4, 2017, 1:34:37 PM7/4/17
to Google App Engine
Hello Raunak, 

How would you describe a use-case typical of your situation? What is here exactly meant by "renaming" an entity? 

A possible solution, based on information at hand, would be based on using Annotation Type ApiTransformer. More detail in the @ApiTransformer subchapter of the "Endpoint Annotations and Syntax" documentation page. 

All other information you deem relevant can prove quite helpful. 

Raunak Gupta

unread,
Jul 6, 2017, 7:54:08 PM7/6/17
to Google App Engine
As an example, if I have a Java POJO like this

class Car {
  private String model;
  private String transmissionType;
  private int year;

  ...
  
}

and my endpoint returns Car, then the response would look something like this

{
    "model": "Porshe 911",
    "transmissionType": "Petrol",
    "year": 2017
}

What I want to do is, rename the entity such that the response looks like...

{
    "model": "Porshe 911",
    "transmission_type": "Petrol",
    "year": 2017
}

Hope this makes more sense now.

George (Cloud Platform Support)

unread,
Jul 7, 2017, 4:57:25 PM7/7/17
to Google App Engine
Hi Raunak, 

Is there no way to do that within your app, and modify names after information is retrieved from the response, alter transmissionType with an underscore at that later point in time? How does this need fit in the overall architecture of your app? 

Raunak Gupta

unread,
Jul 11, 2017, 9:18:19 AM7/11/17
to Google App Engine
I could by creating another POJO, but this seems like a bad approach given one would end up creating 100s of duplicating POJOs. Do you know what Java library Cloud endpoints uses under the hood to convert POJO to Json?

George (Cloud Platform Support)

unread,
Jul 11, 2017, 10:15:27 AM7/11/17
to Google App Engine
Hi Raunak, 

You can find some info on the endpoints-framework 2.0.0-beta.5 API page [1] regarding the library used for endpoints. 

If you need to create POJOs on the fly, you can find some info reading "How to create and then instantiate POJO classes dynamically?" in stackoverflow. [2]

As this seems to boil down to coding, you would be better served by posting your questions on stackoverflow or similar forums, where programmers are ready to share their expertise with you. 

D. T.

unread,
Jul 11, 2017, 3:32:56 PM7/11/17
to Google App Engine
Endpoints uses Jackson under the hood, but it's vendored. Instead use @ApiResourceProperty.

Raunak Gupta

unread,
Jul 12, 2017, 1:54:48 PM7/12/17
to Google App Engine
Many thanks @Daniel Tang. That worked like a charm. 
Reply all
Reply to author
Forward
0 new messages