我有QueueContent类,它已经是两个人的超类。
我得到一个字符串JSON格式包含我需要提取信息。超类是:
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class QueueContent {
private String empresa;
private String empresa_cor;
private String empresa_contato;
private String empresa_url;
private String empresa_telefone;
private String empresa_idioma;
public QueueContent(String empresa, String empresa_cor, String empresa_contato, String empresa_url, String empresa_telefone, String empresa_idioma) {
this.empresa = empresa;
this.empresa_cor = empresa_cor;
this.empresa_contato = empresa_contato;
this.empresa_url = empresa_url;
this.empresa_telefone = empresa_telefone;
this.empresa_idioma = empresa_idioma;
}
public QueueContent() {
}
}
我使用的是龙目生成getter / setter方法)
这是子类:
@Data
public class EmailCameraOffline extends QueueContent {
private Timestamp camera_last_online;
private String camera_nome;
private String empresa_url_plataforma;
public EmailCameraOffline(String empresa, String empresa_cor, String empresa_contato, String empresa_url, String empresa_telefone, String empresa_idioma, Timestamp camera_last_online, String camera_nome, String empresa_url_plataforma) {
super(empresa, empresa_cor, empresa_contato, empresa_url, empresa_telefone, empresa_idioma);
this.camera_last_online = camera_last_online;
this.camera_nome = camera_nome;
this.empresa_url_plataforma = empresa_url_plataforma;
}
public EmailCameraOffline() {
}
}
所以我做:
EmailCameraOffline infosEmail = new ObjectMapper().readValue(content, EmailCameraOffline.class); System.out.println(infosEmail);
而输出是:
EmailCameraOffline (camera_last_online = 2020-03-12 03: 01: 45.0, camera_nome = Pier Cam 1, empresa_url_platform = null)
如何让我的EmailCameraOffline对象有超属性初始化?
一切都应该被加载和初始化就好了,所以美其名曰:
System.out.println(infosEmail.getEmpresa());
应该给预期值。
问题是,在默认的实现toString()
方法(通过完成@Data
AT)EmailCameraOffline
类,其中不包括继承的字段。
为了解决这个问题,你可以“覆盖” @Data
的toString()
执行情况,包括继承的字段,以及使用龙目岛为:
@Data
@ToString(callSuper = true)
public class EmailCameraOffline extends QueueContent {
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句