Skip to main content

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:

HandlerPurpose
JsonTypeHandlerTries Jackson, then Gson, then Fastjson, then Fastjson2 based on available dependencies.
JsonUseForFastjsonTypeHandlerForce Fastjson for JSON serialization/deserialization.
- https://github.com/alibaba/fastjson
JsonUseForFastjson2TypeHandlerForce Fastjson2 for JSON serialization/deserialization.
- https://github.com/alibaba/fastjson2
JsonUseForGsonTypeHandlerForce Gson for JSON serialization/deserialization.
- https://github.com/google/gson
JsonUseForJacksonTypeHandlerForce Jackson for JSON serialization/deserialization.
- https://github.com/FasterXML/jackson-core
BsonListTypeHandlerUse org.bson/com.mongodb for BSON; for List/Set mappings, detects the generic element type.
BsonTypeHandlerUse org.bson/com.mongodb for BSON serialization/deserialization.