My program is written in Java 8, when I use the type of LocalDateTime, it will give me the following error:
No suitable constructor found for type [simple type, class java.time.LocalDateTime]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [B@5976fe6f; line: 1, column: 80] (through reference chain: com.boot.framwork.entity.UserInfo["accessTime"])
The entity is like this:
public class UserInfo implements Serializable {
private static final long serialVersionUID = 1L;
private String username;
private int age;
private LocalDateTime accessTime;
private Date time;
private List<String> list = new ArrayList<String>();
private boolean isMarried;
public UserInfo() {
}
It worked when I didn't use LocalDateTime
It seems to me, that you don't have a JSR310 support. Jackson need some additional configuration to be able to recognize Java 8 Date&Time API data types. You can add it via project dependencies, just add a dependency on this
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.7.4</version>
</dependency>
or if you use a Gradle
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'
Since you use SpringBoot, this should be enough, hence not, create a Bean of type JSR310Module manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With