The Artima Developer Community
Sponsored Link

Java Buzz Forum
Hibernate JSON UserType: simple handling of JSON objects with Jackson

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Fabrizio Fortino

Posts: 10
Nickname: fabriziof
Registered: Aug, 2014

Fabrizio Fortino is an experienced programmer and open source enthusiast.
Hibernate JSON UserType: simple handling of JSON objects with Jackson Posted: Jun 7, 2016 9:40 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Fabrizio Fortino.
Original Post: Hibernate JSON UserType: simple handling of JSON objects with Jackson
Feed Title: Keep it HTTPS
Feed URL: http://fabriziofortino.github.io/feed.xml
Feed Description: No fluff just stuff weblog
Latest Java Buzz Posts
Latest Java Buzz Posts by Fabrizio Fortino
Latest Posts From Keep it HTTPS

Advertisement

Hibernate provides a wide range of mappings to convert SQL data to Java objects and the other way around. In some circumstances, developers may need to define custom types to handle the mapping of a column to a specific type. In the last years, along with the exploding growth of JavaScript, JSON has become the most popular data­-interchange format with lots of supporting libraries that make it easy to read and write models in JSON. Jackson is a widely used high performance Java JSON data processing library. Here I will show you how to create a custom Hibernate UserType that uses Jackson to map generic POJOs to a database column in a transparent fashion.

Add Jackson as dependency to your project

Include the Jackson UserType implementation

Here is the code in charge of handling the marshall/unmarshall of JSON to Java and vice versa. It implements ParameterizedType to allow parameterization of the mapping file. This implementation supports LONGVARCHAR, CLOB and BLOB.

Define the hbm file to instruct Hibernate how to map the defined class to the database table

Below is an example of mapping file for the Person java class. As you can see it contains the status property of type EnumType (provided by Hibernate) and our JSONUserType config property. Parameter classType is the mapped POJO and type is the CLOB column type constant (see class java.sql.Types for more details on constant field values).

Hibernate JSON UserType: simple handling of JSON objects with Jackson was originally published by Fabrizio Fortino at keep it https on June 07, 2014.

Read: Hibernate JSON UserType: simple handling of JSON objects with Jackson

Topic: CUBA Platform – an open source Java framework for rapid application development Previous Topic   Next Topic Topic: JAVA Swing Form Example

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use