ST_AsGeoJSON . , , , , , GeoJSON , Well Known Binary (EWKB), Postgres . , - MVC- JTS.
( ), JPA (, Hibernate 5 Hibernate-Spatial 4), JTS ( ) . WKB (Well Known Binary) , Java, , 64 (8 ) - ! Hibernate ( , SRID ..):
@Column(columnDefinition = "geometry(MultiPolygon,4326)")
private Geometry geom;
Spring, PostGIS application.properties( ):
spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisDialect
Spring ( JPQL , , ..).
, GeoJSON Jackson , JTS, https://github.com/bedatadriven/jackson-datatype-jts:
<dependency>
<groupId>com.bedatadriven</groupId>
<artifactId>jackson-datatype-jts</artifactId>
<version>2.2</version>
</dependency>
Jackson, Spring, bean , :
@Bean
public Jackson2ObjectMapperBuilder objectMapperBuilder() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.modulesToInstall(new JtsModule());
return builder;
}
Jackson, ( , ..), .
Now, when you return the JTS geometry to an object from your Spring MVC controllers, they are automatically converted to GeoJSON geometry. You will have to either replicate the GeoJSON Feature / FeatureCollection structures as classes if you want to use them, or return something (like your Entity) that can easily be mapped to JavaScript in such a structure.