从JSON创建CLOB属性

时间:2016-01-20 17:20:40

标签: java sql json spring clob

我有实体像Maven依赖项一样导入,看起来像这样(简化)

@Entity
public class Person extends Base {

    private String name;

    private Clob biography;
//Getters and setters

我用方法POST

收到这个JSON
{"name":"John Doe",
"biography":"dragonborn"}

我收到了这个错误

"status": 400,
    "error": "Bad Request",
    "exception": "org.springframework.http.converter.HttpMessageNotReadableException",
    "message": "Could not read document: Can not construct instance of java.sql.Clob, 
problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n at
 [Source: java.io.PushbackInputStream@39e31d6a; line: 2, column: 13] (through reference chain: com.example.Person[\"biography\"]); 
nested exception is com.fasterxml.jackson.databind.JsonMappingException: 
Can not construct instance of java.sql.Clob, 
problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n 
at [Source: java.io.PushbackInputStream@39e31d6a; line: 2, column: 13] (through reference chain: com.example.Person[\"biography\"])",
    "path": "/persons"

如果“传记”是String,则创建Person。 如何将JSON属性转换为java.sql.Clob属性? 最好的解决方案是调整ObjectMapper,但我很乐意听到任何建议。谢谢!

1 个答案:

答案 0 :(得分:1)

只需使用

<script language="javascript">
function verif(){
var x = document.getElementById('username').value;
if (x.length == 1 && x.charAt(x.length-1)== "'")
{
  alert("Please provide a valid user name. The user name has to be a alphanumerical starting with a lowercase letter !");
  return false;
}
else if  (x[0] == "'" && x.charAt(x.length - 1) =="'" )
{
return true;
}
else 
{
  var b = x[0] === x[0].toUpperCase();
    if  (b == true )
    {
          alert("Please provide a valid user name. The user name has to be a alphanumerical starting with a lowercase letter !");
          return false;
    }
 }  
}

在DDL for database中将列启动为CLOB