Я использую PostgreSQL с PostGIS для хранения геопространственных данных MultiPolygon
CREATE TABLE voivodeships
(
id INTEGER NOT NULL CONSTRAINT geotable_new_pk PRIMARY KEY,
name VARCHAR,
geometry GEOMETRY(MultiPolygon, 4326);
Я создал Entity, Repository и Controller в Spring Boot следующим образом:
Entity:
@Entity
@Table(name = "voivodeships")
public class Voivodeship {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
private String name;
@Column
private MultiPolygon geometry;
// getters and setters omitted
}
Репозиторий:
public interface VoivodeshipRepository extends JpaRepository<Voivodeship, Long> { }
Контроллер:
@RestController
public class VoivodeshipController {
@Autowired
VoivodeshipRepository voivodeshipRepository;
@GetMapping("/voiv/{id}")
public Voivodeship getVoivodeshipById(@PathVariable(value = "id") Long id) {
return voivodeshipRepository.findById(id).orElseThrow(()->new ResourceNotFoundException("Voivodeship " + id + " not found"));
}
}
Но при localhost:8080/voiv/1
я получаю:
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle
Полное исключение здесь:
<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Oct 23 14:26:44 CEST 2018</div><div>There was an unexpected error (type=Internal Server Error, status=500).</div><div>Type definition error: [simple type, class org.geolatte.geom.crs.AngularUnit]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle (through reference chain: com.kswr.spring.boot.postgis.demo.postgisdemo.model.Voivodeship["geometry"]->org.geolatte.geom.MultiPolygon["coordinateReferenceSystem"]->org.geolatte.geom.crs.Geographic2DCoordinateReferenceSystem["coordinateSystem"]->org.geolatte.geom.crs.EllipsoidalCoordinateSystem2D["axes"]->org.geolatte.geom.crs.GeodeticLongitudeCSAxis[0]->org.geolatte.geom.crs.GeodeticLongitudeCSAxis["unit"]->org.geolatte.geom.crs.AngularUnit["fundamentalUnit"]->org.geolatte.geom.crs.AngularUnit["fundamentalUnit"])</div></body></html>