我为我正在开发的Java实现了一个类。该类具有一个“创建”LocalDateTime属性。但是,当我尝试设置该属性(一次)时,它的setter以某种方式连续调用两次--首先设置我想要的值,然后在不应该发生的第二个调用中将其设置为null。
我已经通过下面的方法进行了跟踪,所有的内容都很好地显示到了第三行。
public static ICEDocument mapDocumentFromSOLR(SolrDocument document) {
ICEDocument result = new ICEDocument();
Date uploaded = (Date) document.getFieldValue("CREATED");
LocalDateTime uploadDate = LocalDateUtils.convertUtcDateToLocalDateTime(uploaded); // custom class
result.setCreated(uploadDate); // **faulty line**
}这节课是为了清晰起见而缩短的:
import java.time.LocalDateTime;
import org.springframework.data.annotation.Transient;
[...]
@JsonIgnoreProperties(ignoreUnknown=true)
public class ICEDocument implements java.io.Serializable {
[...]
@Transient
private LocalDateTime created;
[...]
@JsonDeserialize(using=LocalDateTimeJsonDeserializer.class)
public void setCreated(LocalDateTime created) {
System.out.println("Setting creation date " + created); // added for debugging
this.created = created;
}
} 步骤,我已经尝试解决这个
谢谢你阅读我的长篇文章。
发布于 2016-02-11 20:36:13
调试代码之后,我找到了一行代码,它将属性设置为null。所以我想,这实际上是第二次打电话给策划人,而且运气很差。
但是知道其他因素没有什么问题可能会有帮助,所以我就把这个留在这里,再次感谢。
https://stackoverflow.com/questions/35343787
复制相似问题