[英]Deserializing XML to Object using Jackson mapping Y/N to true/false boolean
I need to map elements in an xml that are listed as Y/N to a boolean (true/false). 我需要将列为Y / N的xml中的元素映射到布尔值(true / false)。
One of the elements in the xml is: xml中的元素之一是:
<parent_node> <due_override_flag>N</due_override_flag> ...more elements </parent_node>
I need to map the 'N'/'Y' to a boolean false/true This is the class I want to element to be mapped to: 我需要将“ N” /“ Y”映射到布尔值false / true。这是我要映射到的元素类:
@JsonRootName("trailer_standard_loads")
@JsonIgnoreProperties(ignoreUnknown=true)
public class StandardLoad {
@JsonProperty("trailer_load_seq")
private Integer trailerLoadSeq;
private String createdBy;
private ZonedDateTime createdDt;
private String updatedBy;
private ZonedDateTime updatedDt;
@JsonProperty("due_override_flag")
private Boolean dueOverrideFlag;
}
I have standard getter and setters. 我有标准的吸气剂和吸气剂。 I don't understand from the documentation how to map Y = true; 我从文档中不了解如何映射Y = true; N = false; N =错误;
Add that logic in setter method 在setter方法中添加该逻辑
@JsonRootName("trailer_standard_loads")
@JsonIgnoreProperties(ignoreUnknown=true)
public class StandardLoad {
@JsonProperty("trailer_load_seq")
private Integer trailerLoadSeq;
private String createdBy;
private ZonedDateTime createdDt;
private String updatedBy;
private ZonedDateTime updatedDt;
private Boolean dueOverrideFlag;
@JsonProperty("due_override_flag")
public void setDueOverrideFlag(String value) {
this.dueOverrideFlag = value.equalsIgnoreCase("Y) ? true : false;
}
public Boolean getDueOverrideFlag() {
return this.dueOverrideFlag;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.