如何在Spring Boot中反序列化/序列化Geometry类型? [英] How to deserialize / serialize type Geometry in spring boot?

查看:1052
本文介绍了如何在Spring Boot中反序列化/序列化Geometry类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体,其属性类型为MultiPolygon和Point;所以我正在发出一个get请求,但这返回了SerializationException.

I have an entity with attributes of type MultiPolygon and Point; so I'm making a get request but this is returning a SerializationException.

我对其进行了研究,发现我必须做一些说明,创建一个配置类,并将相应的依赖项放入pom.xml中.按照我在下面的步骤进行操作:

I researched it and saw that I have to put some notes, create a configuration class and put the corresponding dependency in pom.xml. Follow as I did below:

实体:

package com.zxventures.model;

@Entity
@Table(name = "pdv")
public class PDV implements Serializable {

private static final long serialVersionUID = 1L;

 @Column(name="coverage_area")
 @JsonSerialize(using = GeometrySerializer.class)
 @JsonDeserialize(contentUsing = GeometryDeserializer.class)
 private MultiPolygon coverageArea;

 @Column(name="address")
 @JsonSerialize(using = GeometrySerializer.class)
 @JsonDeserialize(contentUsing = GeometryDeserializer.class)
 private Point address;
}

配置类:

package com.zxventures.config;

@Configuration
public class JacksonConfig {

 @Bean
 public JtsModule jtsModule() {
  return new JtsModule();
 }
}

pom.xml:

<dependency>
<groupId>com.bedatadriven</groupId>
<artifactId>jackson-datatype-jts</artifactId>
<version>2.4</version>
</dependency>

发生异常:

could not deserialize; nested exception is 
org.hibernate.type.SerializationException: could not deserialize

我认为我缺少一些代码,但是我无法检测到它;我想我把看到的所有代码都放在了类似的问题中.

I think I'm missing some code but I can not detect it; I think I put all the code I saw in similar questions.

推荐答案

您正在使用空间数据类型,因此需要包含以下依赖项才能工作

You're using Spatial data types, so need to include below dependency to work

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-spatial</artifactId>
</dependency>

并相应地更改方言,例如org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect

And change dialect accordingly e.g. org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect

请参见空间数据类型

这篇关于如何在Spring Boot中反序列化/序列化Geometry类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆