通过 RestFul 服务发送 PostGIS 对象 (JSON)

发布于 2024-12-31 23:24:55 字数 2145 浏览 4 评论 0原文

全部。

这是我的第一个问题,如果我做错了什么,请原谅。开始了。

我在尝试通过 RestFul 服务发送 PostGIS 对象(实际上是 PGgeometry)时遇到问题。

我试图发送的类是 GPSMessageFormat:

@XmlRootElement(name="position")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType( propOrder = {
    "latitude",
    "longitude",
    "position",
    } )
public class GPSMessageFormat implements Serializable{

  private static final long serialVersionUID = 4178516023632486216L;

  public Double latitude;

  public Double longitude;

  public PointJaxRS position;
}

我已经创建了自己的类来实现 PGgeometry 以便添加所需的标签:

@XmlAccessorType(XmlAccessType.FIELD)
public class PointJaxRS extends PGgeometry {

  private static final long serialVersionUID = 4624155439994995423L;

  public PointJaxRS(){
    super();
  };
}

这是达到的异常:

org.postgis.Geometry does not have a no-arg default constructor.
    this problem is related to the following location:
        at org.postgis.Geometry
        at org.postgis.Point
        at es.datatype.PointJaxRS
        at public es.datatype.PointJaxRS es.datatype.GPSMessageFormat.position
        at es.datatype.GPSMessageFormat
Class has two properties of the same name "m"
    this problem is related to the following location:
        at public double org.postgis.Point.getM()
        at org.postgis.Point
        at es.datatype.PointJaxRS
        at public es.datatype.PointJaxRS es.datatype.GPSMessageFormat.position
        at es.datatype.GPSMessageFormat
    this problem is related to the following location:
        at public double org.postgis.Point.m
        at org.postgis.Point
        at es.datatype.PointJaxRS
        at public es.datatype.PointJaxRS es.datatype.GPSMessageFormat.position
        at es.datatype.GPSMessageFormat

[...] **Other similar errors with all the other fields from PGgeometry**

我认为添加 @XmlAccessorType(XmlAccessType .FIELD) 标签足以仅将类中的属性识别为 json 文件中的字段,但这似乎不适用于继承的属性。另外,我需要 Geometry 有一个无参数的默认构造函数...

我无法将它们作为字符串发送,因为它们将被 Openlayers 接收,所以它需要能够读取 PGgeometry 才能绘制地图上的点。

所以问题是:如何通过 REST 服务发送 JSON 格式的 PostGIS 对象?

all.

This is my first question, so forgive if I do anything wrong. Here we go.

I have a problem while trying to send a PostGIS Object (actually a PGgeometry) through a RestFul service.

The class I'm trying to send is GPSMessageFormat:

@XmlRootElement(name="position")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType( propOrder = {
    "latitude",
    "longitude",
    "position",
    } )
public class GPSMessageFormat implements Serializable{

  private static final long serialVersionUID = 4178516023632486216L;

  public Double latitude;

  public Double longitude;

  public PointJaxRS position;
}

I have created my own class that implements PGgeometry in order to add the needed tags:

@XmlAccessorType(XmlAccessType.FIELD)
public class PointJaxRS extends PGgeometry {

  private static final long serialVersionUID = 4624155439994995423L;

  public PointJaxRS(){
    super();
  };
}

This is the exception that reached:

org.postgis.Geometry does not have a no-arg default constructor.
    this problem is related to the following location:
        at org.postgis.Geometry
        at org.postgis.Point
        at es.datatype.PointJaxRS
        at public es.datatype.PointJaxRS es.datatype.GPSMessageFormat.position
        at es.datatype.GPSMessageFormat
Class has two properties of the same name "m"
    this problem is related to the following location:
        at public double org.postgis.Point.getM()
        at org.postgis.Point
        at es.datatype.PointJaxRS
        at public es.datatype.PointJaxRS es.datatype.GPSMessageFormat.position
        at es.datatype.GPSMessageFormat
    this problem is related to the following location:
        at public double org.postgis.Point.m
        at org.postgis.Point
        at es.datatype.PointJaxRS
        at public es.datatype.PointJaxRS es.datatype.GPSMessageFormat.position
        at es.datatype.GPSMessageFormat

[...] **Other similar errors with all the other fields from PGgeometry**

I thought that adding the @XmlAccessorType(XmlAccessType.FIELD) tag was enough to recognize only the attributes from the class as fields in the json file, but it seems that this does not work for inherited attributes. In addition, I would need Geometry to have a no-arg default constructor...

I can't send them as String because they are going to be received by Openlayers, so it needs to be able to read the PGgeometry in order to draw the points in a map.

So the question is: what can I do to send PostGIS objets in JSON format through rest services?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文