spring-projects / spring-projects/spring-data-rest
Could not write JSON document: java.util.Optional cannot be cast to java.lang.String [DATAREST-1063]
Open
@odrotbohm is already working on this.
Since Dec 31, 2020.
in: repository
status: feedback-provided
type: bug
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Denis opened DATAREST-1063 and commented
When POST new object I have such response:
Could not write JSON document: java.util.Optional cannot be cast to java.lang.String (through reference chain: org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1[\"content\"]->domain.Post[\"lastModifiedDate\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.util.Optional cannot be cast to java.lang.String (through reference chain: org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1[\"content\"]->domain.Post[\"lastModifiedDate\”])
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.AbstractAuditable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import java.util.Date;
/**
* Created by exx on 27/04/2017.
*/
@Entity
public class Post extends AbstractAuditable<Post, Long>{
@Basic
@Getter @Setter private Date publishDate;
@Basic(optional = false)
@Getter @Setter private String title;
@Basic(optional = false)
@Getter @Setter private String body;
@Basic(optional = false)
@Getter @Setter private String preview;
@Basic(optional = false)
@Getter @Setter private String author;
}
/**
* Created by exx on 27/04/2017.
*/
@RepositoryRestResource
public interface PostRepository extends PagingAndSortingRepository<Post, Long> {
}
Affects: 3.0 M2 (Kay)
1 votes, 3 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.