I am trying to convert an object to another using gson. while converting the gson getting a runtime exception saying: "unable to invoke no-args constructor for interface java.sql.clob. Registering an instancecreator with gson for this type may fix the problem." I am not quite sure why this exception is occuring. below is the code.
Entity 1:
@Entity
@Table(name="Template")
public class TemplateData implements serializable{
@Column(name="template_id")
public Integer templateId;
@Lob
@Column(name="template_Data")
public Clob templateData;
@Lob
@Column(name="template_Total")
public Clob templateTotal;
public Integer getTemplateId(){
return templateId;
}
public void setTemplateId(Integer templateId){
this.templateId = templateId;
}
public Clob getTemplateData(){
return templateData;
}
public void setTemplateId(Clob templateData){
this.templateData = templateData;
}
public Clob getTemplateTotal(){
return templateTotal;
}
public void setTemplateTotal(Clob templateTotal){
this.templateTotal = templateTotal;
}
}
Entity 2-
@Entity
@Table(name="Template_Audit")
public class TemplateAuditData implements serializable{
@Column(name="template_Audit_id")
public Integer templateAudtId;
@Column(name="template_id")
public Integer templateId;
@Lob
@Column(name="template_Data")
public Clob templateData;
@Lob
@Column(name="template_Total")
public Clob templateTotal;
public Integer getTemplateAuditId(){
return templateAudtId;
}
public void setTemplateId(Integer templateAudtId){
this.templateAudtId = templateAudtId;
}
public Integer getTemplateId(){
return templateId;
}
public void setTemplateId(Integer templateId){
this.templateId = templateId;
}
public Clob getTemplateData(){
return templateData;
}
public void setTemplateId(Clob templateData){
this.templateData = templateData;
}
public Clob getTemplateTotal(){
return templateTotal;
}
public void setTemplateTotal(Clob templateTotal){
this.templateTotal = templateTotal;
}
}
creating an object for templatedata and this object has some data.
TemplateData td = new TemplateData();
//td has some data and I am able to save the TemplateData using hibernate //trying to convert templatedata into templateauditdata
TemplateAuditData tad = new Gson().fromJson(new Gson().toJson(td), new TypeToken<TemplateAuditData>(){}.getType());
object 'tad' is giving me the above runtime exception.
Can anyone help me with the fix please. I am unable to understand the issue. Thank you in advance.