The demo project with mapping of Java objects inheritance into PostgreSQL JSONB columns via Jackson and MyBatis.
To build & test:
$ ./gradlew build test
To run application on localhost:
$ ./gradlew bootRun
Required PostgreSQL
running on port 5432
with database schema.
It can be done with Docker container:
$ docker run \
--name postgres \
-e POSTGRES_DB="postgres" \
-e POSTGRES_USER="postgres" \
-e POSTGRES_PASSWORD="postgres" \
-v postgres_data:/var/lib/postgresql \
-v ${PWD}/src/main/resources/sql/init.sql:/docker-entrypoint-initdb.d/1.init.sql \
-v ${PWD}/src/main/resources/sql/data.sql:/docker-entrypoint-initdb.d/2.data.sql \
-p 5432:5432 \
-d postgres:latest
To package the application into jar file:
$ ./gradlew bootJar
To build the application docker image:
$ docker-compose build
To run in Docker with PostgreSQL database:
$ docker-compose up -d
To stop the application and PostgreSQL database:
$ docker-compose down --volumes
SQL:
id | 1
type | VEHICLE
latitude | 45.047579
longitude | 38.963983
course | 10
speed | 15
attributes | {"model": "Toyota Camry", "regNumber": "A 123 BC 777"}
JSON:
{
"id": 1,
"type": "VEHICLE",
"latitude": 45.047579,
"longitude": 38.963983,
"course": 10,
"speed": 15,
"model": "Toyota Camry",
"regNumber": "A 123 BC 777"
}
SQL:
id | 3
type | EMPLOYEE
latitude | 45.026158
longitude | 38.927763
course | 30
speed | 35
attributes | {"name": "John Doe", "phoneNumber": "8-800 2000 600"}
JSON:
{
"id": 3,
"type": "EMPLOYEE",
"latitude": 45.026158,
"longitude": 38.927763,
"course": 30,
"speed": 35,
"name": "John Doe",
"phoneNumber": "8-800 2000 600"
}
Thanks to @0ffer, it was his idea and initial implementation.