为什么LocalDateTime没有String构造函数? [重复]

问题描述 投票:0回答:1

我最近尝试通过Spring MVC将JSON数据发布到具有LocalDateTime属性的POJO时遇到以下错误:

LocalDateTime

为了解决此错误,我必须将设置器从]更改为>

no String-argument constructor/factory method to deserialize from String value

to

public void setToDate(LocalDateTime toDate) {
    this.toDate = toDate;
}

[这让我想到了一个问题,为什么public void setToDate(String toDate) { this.toDate = LocalDateTime.parse(toDate); } 为什么不具有LocalDateTime构造函数以及静态String方法?

[我最近尝试通过Spring MVC将JSON数据发布到具有LocalDateTime属性的POJO时遇到以下错误:没有用于反序列化的String-argument构造函数/工厂方法...

java java-8 java-time java-date
1个回答
0
投票
(几乎)parse()中的所有类都没有任何构造函数,至少没有公共构造函数。您只能通过调用静态工厂方法之一(其中parse()是其中之一)来创建这些类的实例。
© www.soinside.com 2019 - 2024. All rights reserved.