简体   繁体   中英

GWT emulation for com.google.api.client.json.GenericJson

Is there a way to use this com.google.api.client.json.GenericJson package along with any Object that extends from it in GWT?

If none, what is the approch to be use the models from com.google.api.client.json.* with GWT?

google-http-java-client is not a GWT library, so it's not an option for GWT.

To deal with JSON you have different alternatives:

  • the most tiresome to me is the classic com.google.gwt.json.client.
  • A better approach is to use elemental.json included with gwt-elemental, which can be run in gwt and jvm
  • If you prefer handle json as normal POJOs in your code you have autobeans in GWT (Also can be used in JVM)
  • I would rather use gwtquery Databinding since it's much easier, light way, the syntax to consume webservices is quite simple, and it's also usable in the JVM.

[Edited]

Other options

  • Overlay types you have to write as many methods as attributes you want to access. It is tedious because you have to deal with jsni and it's issues. gwtquery databinding uses basically this approach, but facilitating the work with its generator. Obviously Overlay types do not work in the JVM, so you cannot test that logic in your presenters.
  • The future of GWT is to use JsInterop so as you can access jso properties just defining interfaces. JsInterop is a feature very experimental in 2.7.0 which would be stable in gwt-3.0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM