I am currently using Hibernate 6.4.4 version, along with spanner-hibernate-dialect 3.3.0 version and google-cloud-spanner-jdbc 2.16.1 version. But still facing the below error as:
org.springframework.dao.InvalidDataAccessApiUsageException: Could not deserialize string to java type: JsonJavaType(model.Template)
@Column(name="TemplateObj")
@JdbcTypeCode( SqlTypes.JSON )
private Template template;
Below is the model class of Template
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Template {
private String id;
private String vendor;
private String acc;
private String schemaVersion;
private String icon;
private String type;
private Descriptor descriptor;
private DetailTemplate detailTemplate;
private String accountId;
private Boolean hasAccount;
private Boolean canTestConnection;
private String dataSourceType;
private Boolean runNowSupported;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Descriptor {
private String displayName;
private String description;
private String docRef;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DetailTemplate {
private String type;
private Descriptor descriptor;
@NotEmpty(message = "{detailTemplate.properties.required}")
private List<Property> properties;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Property {
private String id;
private boolean required;
private boolean disabled;
private String validation;
private String default_value;
private String type;
private Descriptor descriptor;
private List<Option> options;
private DependsOn depends_on;
private boolean secret;
private boolean disableOnEdit;
private Integer minDays;
private String helperText;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Option {
private String id;
private String displayName;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DependsOn {
private String field;
private String value;
}
Below is sample data of TemplateObj column which is to be stored in Spanner DB
{
"canTestConnection": true,
"detailTemplate": {
"properties": [
{
"descriptor": {
"description": "Select multiple regions",
"displayName": "Region",
"docRef": "https://guide.com"
},
"id": "region",
"options": [
{
"displayName": "us-east",
"id": "us-east"
},
{
"displayName": "canada",
"id": "canada"
}
],
"required": true,
"type": "multi-select"
}
]
},
"descriptor": {
"description": "Sample",
"displayName": "Test Name",
"docRef": "https://guide.com"
},
"hasAccount": true,
"icon": "http://svg_link",
"id": "abc",
"schemaVersion": "1.0",
"type": "xyz",
"vendor": "Test"
}
I have also defined as below in my application.yaml file
spring:
jpa:
properties:
hibernate:
dialect: com.google.cloud.spanner.hibernate.SpannerDialect
We were using @Type(type = "com.google.cloud.spanner.hibernate.types.SpannerJsonType") before while using hibernate 5.x version, but seems now just don't understand why the spanner custom column types is not there for json object
Any suggestions? I want to store the java object in json format.
ConnectorTemplateclass seems valid, but contains two fields that are themselves structured classes;DescriptorandConfigTemplate. Would you mind sharing those as well?