Last updated: 2024-04-15

  1. Learn
  2. Documentation
  3. Data Objects

Persisting JSON with Spring Data

Basically every modern database system has its own data type to persist JSON. Using this type ensures correct formatting of the input, as well as other advantages such as faster I/O.

With Hibernate 6 we can directly map our JSON fields using Hibernates @JdbcTypeCode(SqlTypes.JSON) annotation at our entities. The technical backgrounds are explained in this article.

Bootify's Free plan also supports JSON fields. For this we can create our custom model in the Data Objects tab and select the new model as a field type at the entity. Depending on the database a certain type and column definition is necessary - this is automatically provided by Bootify together with all the setup around it.

We begin by clicking start project - no registration required. Then we go to the Data Objects tab and first create the object "PartDetailsDimensions" with its three fields.

Adding the PartDetailsDimensions data object

Adding the PartDetailsDimensions data object

Now we create the object "PartDetails". Since "PartDetailsDimensions" already exists, we can select it directly as a custom type.

Adding the PartDetails

Adding the PartDetails

Finally we go back to the "Entities" tab and create the CarPart entity if not already existing. Here we can now add the field "partDetails" with its corresponding type PartDetails.

Adding the new field to our entity

Adding the new field to our entity

That's it!

Reading and writing the partDetails now works like a charm with Hibernate taking care of all the mappings. Bootify creates proper field types and annotations based on the selected database, and the runnable source code can be downloaded right away!

Start Project
No registration required