Skip to main content
Hint

This article is generated by AI translation.

JSON Serialization Handler

JSON serialization handlers are located in the net.hasor.dbvisitor.types.handler.json package. Through serialization handlers, you can store Java objects as JSON in text columns of the database.

Use in object mapping
public class User {
@Column(typeHandler = JsonTypeHandler.class)
private UserExtInfo moreInfo;

// getters and setters omitted
}
Use in SQL statements
update users
set more_info = #{arg1, typeHandler=net.hasor.dbvisitor.types.handler.json.JsonTypeHandler}
where id = #{arg0}
info

Before using JSON serialization handlers, you need to add the corresponding JSON library dependency to your project.

Built-in Implementations

JSON Serialization

HandlerDescription
JsonTypeHandlerAuto-detects, tries Jackson → Gson → Fastjson → Fastjson2 in order to find an available JSON library
JsonUseForJacksonTypeHandlerUses Jackson
JsonUseForGsonTypeHandlerUses Gson
JsonUseForFastjsonTypeHandlerUses Fastjson
JsonUseForFastjson2TypeHandlerUses Fastjson2

BSON Serialization

HandlerDescription
BsonTypeHandlerUses MongoDB BSON library for serialization/deserialization
BsonListTypeHandlerBSON-based handling for List, Set and other collection fields, with automatic generic type detection