2

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

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:

Entity:

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;
}

Config class:

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>

The exception occurs:

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.

philabreu
  • 55
  • 1
  • 7

2 Answers2

2

I had the same issue and added below line to application.properties then it works.

spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisDialect
caglar
  • 380
  • 3
  • 8
0

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

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

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

See Spatial data types

Sukhpal Singh
  • 2,130
  • 9
  • 20
  • When I put these snippets, I now get a `java.io.StreamCorruptedException: invalid stream header: 00000000` I researched, but I did not find any solution for spatial type. – philabreu Jul 11 '19 at 19:01
  • 1
    Bingo! Along with what you said, I had to change `import org.geojson.MultiPolygon; import org.geojson.Point;` per `import com.vividsolutions.jts.geom.MultiPolygon; import com.vividsolutions.jts.geom.Point;` Thanks very much! – philabreu Jul 11 '19 at 19:26