2

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.

4
  • The reason that the custom column type for JSON is not in the Hibernate 6.x dialect anymore, is that Hibernate 6.x has built-in support for JSON. There is therefore no longer need for a custom type for JSON. Commented Apr 15, 2024 at 6:45
  • The most likely reason for this error message is that there is a mismatch between your model classes and the JSON string that you are trying to deserialize. The ConnectorTemplate class seems valid, but contains two fields that are themselves structured classes; Descriptor and ConfigTemplate. Would you mind sharing those as well? Commented Apr 15, 2024 at 6:56
  • @KnutOlavLøite I have updated the description with required structured classes Commented Apr 15, 2024 at 10:25
  • @TanushreeBS Did you manage to solve it? Commented Sep 3, 2024 at 14:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.