8.5 JSON Serialization
Hint
This article is generated by AI translation.
JSON handlers live in net.hasor.dbvisitor.types.handler.json; add the dependencies you need. These handlers serialize Java objects to JSON strings for storage.
- JSON is the most common serialization format.
Use a serialization handler in object mapping
public class User {
@Column(typeHandler = net.hasor.dbvisitor.types.handler.json.JsonTypeHandler)
private UserExtInfo moreInfo;
// getters and setters omitted
}
Use a serialization handler in SQL
update
users
set
more_info = #{arg1, typeHandler=net.hasor.dbvisitor.types.handler.json.JsonTypeHandler}
where
id = #{arg0}
JSON serializers
dbVisitor supports four popular JSON providers for serialization and deserialization:
| Handler | Purpose |
|---|---|
| JsonTypeHandler | Tries Jackson, then Gson, then Fastjson, then Fastjson2 based on available dependencies. |
| JsonUseForFastjsonTypeHandler | Force Fastjson for JSON serialization/deserialization. - https://github.com/alibaba/fastjson |
| JsonUseForFastjson2TypeHandler | Force Fastjson2 for JSON serialization/deserialization. - https://github.com/alibaba/fastjson2 |
| JsonUseForGsonTypeHandler | Force Gson for JSON serialization/deserialization. - https://github.com/google/gson |
| JsonUseForJacksonTypeHandler | Force Jackson for JSON serialization/deserialization. - https://github.com/FasterXML/jackson-core |
| BsonListTypeHandler | Use org.bson/com.mongodb for BSON; for List/Set mappings, detects the generic element type. |
| BsonTypeHandler | Use org.bson/com.mongodb for BSON serialization/deserialization. |