Package org.dbunit.ext.postgresql
Class JsonType
java.lang.Object
org.dbunit.dataset.datatype.DataType
org.dbunit.dataset.datatype.AbstractDataType
org.dbunit.ext.postgresql.JsonType
Adapter to handle conversion between PostgreSQL native
json/
jsonb types and Strings.
PostgreSQL requires a bound parameter's declared type to match its
target json/jsonb column exactly - it has no implicit cast
between the two - so one instance handles only the single sql type name it
was constructed with. PostgresqlDataTypeFactory constructs the
matching instance for each column automatically; there is normally no need
to instantiate this class directly.
This class only shuttles the column's raw text between the driver and
the dataset; it does not compare JSON values semantically. Use
IsActualEqualToExpectedJsonValueComparer
to compare json/jsonb column values by their parsed document structure
instead of raw text.
- Since:
- 3.5.0
- Author:
- Jeff Jensen
-
Field Summary
Fields inherited from class org.dbunit.dataset.datatype.DataType
BIGINT, BIGINT_AUX_LONG, BINARY, BIT, BLOB, BOOLEAN, CHAR, CLOB, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, LONGNVARCHAR, LONGVARBINARY, LONGVARCHAR, NCHAR, NUMERIC, NVARCHAR, REAL, RELATIVE_DATE_TIME_PARSER, SMALLINT, TIME, TIMESTAMP, TINYINT, UNKNOWN, VARBINARY, VARCHAR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the sql type name this instance handles.getSqlValue(int column, ResultSet resultSet) Returns the specified column value from the specified resultset object.voidsetSqlValue(Object value, int column, PreparedStatement statement) Set the specified value to the specified prepared statement object.Returns the specified value typecasted to thisDataTypeMethods inherited from class org.dbunit.dataset.datatype.AbstractDataType
areObjectsEqual, compare, compareNonNulls, getSqlType, getTypeClass, isDateTime, isNumber, loadClass, loadClass, toStringMethods inherited from class org.dbunit.dataset.datatype.DataType
asString, forObject, forSqlType, forSqlTypeName, isExtendedSyntax
-
Constructor Details
-
JsonType
Creates a data type adapter for the given PostgreSQL JSON sql type name.- Parameters:
sqlTypeName- The sql type name,"json"or"jsonb", needed to invoke thesetType()method on the PGobject class.
-
-
Method Details
-
getSqlValue
Description copied from class:DataTypeReturns the specified column value from the specified resultset object.- Overrides:
getSqlValuein classAbstractDataType- Parameters:
column- the column index to read, starting at 1.resultSet- the result set to read the column value from.- Returns:
- the column value.
- Throws:
SQLException- if a database access error occurs.TypeCastException- if the value cannot be typecast to thisDataType.
-
setSqlValue
public void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException Description copied from class:DataTypeSet the specified value to the specified prepared statement object.- Overrides:
setSqlValuein classAbstractDataType- Parameters:
value- the value to bind.column- the parameter index to bind to, starting at 1.statement- the prepared statement to bind the value on.- Throws:
SQLException- if a database access error occurs.TypeCastException- if the value cannot be typecast to thisDataType.
-
typeCast
Description copied from class:DataTypeReturns the specified value typecasted to thisDataType- Specified by:
typeCastin classDataType- Parameters:
value- the value to typecast.- Returns:
- the typecast value.
- Throws:
TypeCastException- if the value cannot be typecast to thisDataType.
-
getSqlTypeName
Returns the sql type name this instance handles.- Overrides:
getSqlTypeNamein classDataType- Returns:
"json"or"jsonb", whichever sql type name this instance was constructed with.
-