H2gis database giving exception while inserting in a JSONB column

Viewed 48

I am using PostGIS as actual database and H2gis for integration tests.

The entity class is as below:

    @Entity
   @Table(name = "AIRPORT")
   @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
   public class AirportEntity implements Serializable {

      private static final long serialVersionUID = 1L;

      @Type(type = "jsonb")
      @Column(columnDefinition = "jsonb", name = "airport_info")
      private List<Map<String,String>> airportInfo;
}

Below is the code in the SpringBoot Test:

        AirportEntity airportEntity = new AirportEntity();
        String json = new String(Files.readAllBytes(Paths.get('Airports.json_file_path')));
        List<Map<String, String>> list = new Gson().fromJson(json, new TypeToken<List<Map<String, String>>>() {
        }.getType());
        airportEntity.setAirportInfo(list);
        reportsDataService.saveAirportRecord(airportEntity);

I am using below sql to create jsonb datatype in h2gis.

CREATE TYPE "JSONB" AS text; 

When I am running the above test case , below exception is thrown

Caused by: org.h2.jdbc.JdbcSQLDataException: Serialization failed, cause: "java.io.NotSerializableException: com.fasterxml.jackson.databind.node.ArrayNode"

Is there any way to avoid this exception ?

0 Answers
Related