Reputation: 393
I researched a lot about it, but I wasn't able to reach a conclusion about this matter.
I'm creating a new front-end in GWT, using GWT-Platform and GIN, for an existing application. But I can't figure out which is the best way to interact with the existing REST API.
What I found up to now is that I can use RequestBuilder to do the calls, and that also exists the RestyGWT framework for REST communications. But I don't know how to integrate any of them with GIN Injector. And I have doubts on how to translate the JSON return from the service to the JTO available in the client code translated by GWT.
The last one specially due to a legacy code that translate the Beans from the server to a kind of generic Json format.
So what I want to know is do anybody have experience integrating legacy backend to a new GWT front-end with REST. How they integrate both? How they solve, if experienced, the Beans integration?
Upvotes: 3
Views: 737
Reputation: 628
I agree with Ümit, If you are worried about the "communication" between backend and frontend don´t get stress:
Something like:
public String serializeToJson(YoutEntity report) {
AutoBean<YoutEntity > bean = AutoBeanUtils.getAutoBean(report);
return AutoBeanCodex.encode(bean).getPayload();
}
public YoutEntity deserializeCompanyFromJson(String json) {
AutoBean<YoutEntity > bean =
AutoBeanCodex.decode(factoryYourEntity, YoutEntity .class, json);
return bean.as();
}
is perfectly possible using Autobeans!
And using GWT you can share your entities between Client and Server, so you don´t need to touch anything.
Also, in our last project using Apache Wink as a REST client, in the server using the correct annotations we were able to have the Entity automatically from the JSON, so is even easier (but I think most of the REST libraries can do the same).
Thanks!
Upvotes: 1
Reputation: 17499
Your question touches a couple of different aspects both client-side but also server-side.
In general there is nothing special about integration between GWT
and a REST API
.
On the GWT side there are different ways to consume a REST API:
GIN
per se doesn't have anything to do with the communication with a REST API.
It's only responsible for dependency injection on the client side.
The translation of beans to JSON depends on the backend. Spring
can basically automatically serialize Java beans into JSON using Jackson
.
Upvotes: 0