如何在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
请参见空间数据类型