我非常兴奋地使用GWT Maps API来编写一个服务,该服务在其界面中使用LatLng和LatLngBounds ......只是为了在运行时发现那些类没有实现Serializable,可能是因为它们是Javascript本机对象。
那么使用GWT在服务器端使用位置数据类型的最佳方法是什么? 是否有任何库已经提供可序列化的类和转换到/来自LatLng&company? 或者每个人都写自己的包装?
I was so excited to use GWT Maps API that wrote a service which takes LatLng and LatLngBounds in its interface... Only to find out at runtime that those classes do not implement Serializable, probably because they are Javascript native objects.
What would be the best approach to work with location data types on the server side with GWT then? Are there any libraries which already provide serializable classes and conversion to/from LatLng & company? Or everybody just writes their own wrappers?
最满意答案
看看我写的这些代码是否有助于你:
https://github.com/dartmanx/mapmaker/blob/master/src/main/java/org/jason/mapmaker/client/util/GoogleMapUtil.java
GWT提供了为不实现Serializable(或IsSerializable)的类创建自定义字段序列化器的功能。 但是,JavaScriptObject确实很奇怪,并且不允许您直接访问Java端的任何数据成员。 因此,编写序列化器将充其量只是一个挑战。
您可能还希望查看google的文档,了解可以返回哪些值:
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#passing-javascript
See if any of this code I wrote helps you out:
https://github.com/dartmanx/mapmaker/blob/master/src/main/java/org/jason/mapmaker/client/util/GoogleMapUtil.java
GWT provides the ability to create Custom Field Serializers for classes that don't implement Serializable (or IsSerializable). However, JavaScriptObject is an odd duck indeed and doesn't let you directly access any of its data members on the Java side. So, writing a serializer is going to be a challenge at best.
You may also wish to have a look at google's docs about what sorts of values can be returned:
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#passing-javascript
更多推荐
发布评论