elasticsearch,jackson,spring-data,Spring,Spring Mvc,elasticsearch,Jackson,Spring Data" /> elasticsearch,jackson,spring-data,Spring,Spring Mvc,elasticsearch,Jackson,Spring Data" />

Spring 未能将源{}映射到实体

Spring 未能将源{}映射到实体,spring,spring-mvc,elasticsearch,jackson,spring-data,Spring,Spring Mvc,elasticsearch,Jackson,Spring Data,使用Spring Data elasticsearch从elasticsearch读取文档时,我遇到以下错误: 错误SearchController-嵌套异常:未能将源{文档数据}映射到书本 @Entity @Table(name="books") @Document(indexName="booksearchserver",type="book") public class Book { @org.springframework.data.annotation.Id @Id @Column(n

使用Spring Data elasticsearch从elasticsearch读取文档时,我遇到以下错误:

错误SearchController-嵌套异常:未能将源{文档数据}映射到书本

@Entity
@Table(name="books")
@Document(indexName="booksearchserver",type="book")
public class Book {
@org.springframework.data.annotation.Id
@Id
@Column(name="bookIsbn")
@Field(type = FieldType.Long, store = true)
private String bookIsbn;

@Column(name="bookTitle")
@Field(type = FieldType.String, store = true)
private String bookTitle;


@Column(name="authorId")
@Field(type = FieldType.Integer, store = true)
private int bookAuthorId;

@Column(name="bookLanguage")
@Field(type = FieldType.String, store = true)
private String bookLanguage;

@Column(name="bookPublisherId")
@Field(type = FieldType.Integer, store = true)
private short bookPublisherId;

@Column(name="bookReleaseDate")
@Field(type = FieldType.Date, store = true, format = DateFormat.custom, pattern="yyyy-MM-dd HH:mm:ss +SSSS")
private Date bookReleaseDate;

@JsonIgnore
@Column(name="bookNoOfChapters")
private short bookNoOfChapters;

@JsonIgnore
@Column(name="bookNoOfPages")
private short bookNoOfPages;

@JsonIgnore
@Column(name="bookNoOfWords")
private int bookWordCount;

@JsonIgnore
@Column(name="bookPrecededByIsbn" )
private long bookPrecededBy;

@JsonIgnore
@Column(name="bookFollowedByIsbn")
private long bookFollowedBy;

@Column(name="bookDescription")
@Field(type = FieldType.String, store = true )
private String bookDescription;

@JsonIgnore
@Column(name="bookCoverImage")
private String bookCover;
我的控制器

@RequestMapping(value="/isbnSearch" ,method = RequestMethod.POST)
public String isbnSearch(@RequestParam("bookIsbn") String bookIsbn, Model m) {
    try{
        logger.info("Search for Book by ISBN:" + bookIsbn);
        Book book = searchServices.getBookByIsbn(bookIsbn);
        int authorId = book.getBookAuthorId();
        logger.info("Author ID is " + authorId );
        m.addAttribute("Book", book);
        return "showBook";
    }catch(Exception e){
        logger.error("Nested Exception : "+e.getMessage());
        m.addAttribute("error", e.getMessage());
        return "showError";
    }
}
SearchServerImpl

public Book getBookByIsbn(String isbn) {
//       try{
         Book book = esdao.findBybookIsbn(isbn);
         logger.info(""+ book.getBookTitle());
         return book;
//       }catch(ElasticsearchException ese){
//           logger.error("Nested Exception : " + ese.getMessage());
//           throw ese;
//       }catch(NullPointerException npe){
//           logger.error("Accessing NULL Class");
//           throw npe;
//       }
}
Esdao存储库

package co.in.searchServer.repository;

import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import co.in.searchServer.model.Book;

public interface ESDao extends ElasticsearchRepository<Book,String> {
    Iterable<Book> search(QueryBuilder arg0);
    Book findBybookIsbn(String isbn);
//  <S extends Book> S index(S arg0);
}
package co.in.searchServer.repository;
导入org.elasticsearch.index.query.QueryBuilder;
导入org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
导入co.in.searchServer.model.Book;
公共接口ESDao扩展了ElasticsearchRepository{
Iterable搜索(QueryBuilder arg0);
BookFindBybookisbn(字符串isbn);
//S指数(S arg0);
}

请为我提供一些解决此问题的建议和经验

我知道引发此错误是因为Java无法将json中的自定义日期格式映射到实体属性
bookReleaseDate
。因此,我们必须添加@JsonProperty注释,如下所示:

  @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss +SSSS")
  @Column(name="bookReleaseDate")
  @Field(type = FieldType.Date, store = true, format = DateFormat.custom, pattern="yyyy-MM-dd HH:mm:ss +SSSS")
  private Date bookReleaseDate;