title: How to support xsl:nil with Jackson > 2.12
body: <p>I'm calling a webservice which returns following XML datastructure:</p>
  <pre><code>&lt;ArrayOfEmployee&gt;
   &lt;Employee&gt;
    &lt;EmployerNumber&gt;1&lt;/EmployerNumber&gt;
    &lt;EmployeeNumber&gt;1&lt;/EmployeeNumber&gt;
    &lt;FirstName&gt;John&lt;/FirstName&gt;
    &lt;LastName&gt;Doe&lt;/LastName&gt;
    &lt;CurrentWorkscheme&gt;| 8 | 8 | 8 | 8 | 8 | 0 | 0 |&lt;/CurrentWorkscheme&gt;
    &lt;StartDate&gt;2018-01-01T00:00:00&lt;/StartDate&gt;
    &lt;EndDate xsi:nil=&quot;true&quot;/&gt;
   &lt;/Employee&gt;
   &lt;Employee&gt;
   &lt;EmployerNumber&gt;1&lt;/EmployerNumber&gt;
   &lt;EmployeeNumber&gt;2&lt;/EmployeeNumber&gt;
   &lt;FirstName&gt;Jane&lt;/FirstName&gt;
   &lt;LastName&gt;Doe&lt;/LastName&gt;
   &lt;CurrentWorkscheme&gt;| 8 | 8 | 8 | 8 | 8 | 0 | 0 |&lt;/CurrentWorkscheme&gt;
   &lt;StartDate&gt;2018-12-01T00:00:00&lt;/StartDate&gt;
   &lt;EndDate xsi:nil=&quot;true&quot;/&gt;
  &lt;/Employee&gt;
  &lt;/ArrayOfEmployee&gt;
  </code></pre>
  <p>I'm using spring boot 2.5.5, which includes Jackson 2.12.5, and I have added following dependency to my gradle build:</p>
  <pre><code>implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.5'
  </code></pre>
  <p>I try to deserialize (in a unittest) as follows:</p>
  <pre><code>XmlMapper mapper = new XmlMapper();
  ArrayOfEmployeeDto result = mapper.readValue(xmlSample, ArrayOfEmployeeDto.class);
  </code></pre>
  <p>With following two types defined:</p>
  <pre><code>public class ArrayOfEmployeeDto {
  
      @JacksonXmlElementWrapper(useWrapping = false)
      @JsonProperty(&quot;Employee&quot;)
      private List&lt;EmployeeDto&gt; employees = new ArrayList&lt;&gt;();
  
      public ArrayOfEmployeeDto() {
      }
  
      public List&lt;EmployeeDto&gt; getEmployees() {
          return employees;
      }
  
      public void setEmployees(List&lt;EmployeeDto&gt; employees) {
          this.employees = employees;
      }
  }
  </code></pre>
  <p>and</p>
  <pre><code>@JsonDeserialize(builder=EmployeeDto.Builder.class)
  public class EmployeeDto {
  
      private final String employeeNumber;
      private final String employerNumber;
      private final String firstName;
      private final String lastName;
      private final String currentWorkScheme;
      private final LocalDateTime startDate;
      private final LocalDateTime endDate;
  
      public EmployeeDto(String employeeNumber,
                         String employerNumber,
                         String firstName,
                         String lastName,
                         String currentWorkScheme,
                         LocalDateTime startDate,
                         LocalDateTime endDate) {
          this.employeeNumber = employeeNumber;
          this.employerNumber = employerNumber;
          this.firstName = firstName;
          this.lastName = lastName;
          this.currentWorkScheme = currentWorkScheme;
          this.startDate = startDate;
          this.endDate = endDate;
      }
  
      // All the getters here...
  
      @JsonPOJOBuilder
      public static final class Builder {
          private String employeeNumber;
          private String employerNumber;
          private String firstName;
          private String lastName;
          private String currentWorkScheme;
          private LocalDateTime startDate;
          private LocalDateTime endDate;
  
          public Builder() {
          }
  
          @JsonSetter(&quot;EmployeeNumber&quot;)
          public Builder withEmployeeNumber(String employeeNumber) {
              this.employeeNumber = employeeNumber;
              return this;
          }
  
          @JsonSetter(&quot;EmployerNumber&quot;)
          public Builder withEmployerNumber(String employerNumber) {
              this.employerNumber = employerNumber;
              return this;
          }
  
          @JsonSetter(&quot;FirstName&quot;)
          public Builder withFirstName(String firstName) {
              this.firstName = firstName;
              return this;
          }
  
          @JsonSetter(&quot;LastName&quot;)
          public Builder withLastName(String lastName) {
              this.lastName = lastName;
              return this;
          }
  
          @JsonSetter(&quot;CurrentWorkscheme&quot;)
          public Builder withCurrentWorkScheme(String currentWorkScheme) {
              this.currentWorkScheme = currentWorkScheme;
              return this;
          }
  
          @JsonSetter(&quot;StartDate&quot;)
          @JsonFormat(pattern = &quot;yyyy-MM-dd'T'HH:mm:ss&quot;)
          @JsonDeserialize(using = LocalDateTimeDeserializer.class)
          public Builder withStartDate(LocalDateTime startDate) {
              this.startDate = startDate;
              return this;
          }
  
          @JsonSetter(&quot;EndDate&quot;)
          @JsonFormat(pattern = &quot;yyyy-MM-dd'T'HH:mm:ss&quot;)
          @JsonDeserialize(using = LocalDateTimeDeserializer.class)
          public Builder withEndDate(LocalDateTime endDate) {
              this.endDate = endDate;
              return this;
          }
  
          public EmployeeDto build() {
              return new EmployeeDto(employeeNumber, employerNumber, firstName, lastName, currentWorkScheme, startDate, endDate);
          }
      }
  }
  </code></pre>
  <p><em>The error I get is com.fasterxml.jackson.databind.JsonMappingException: Undeclared namespace prefix &quot;xsi&quot; (for attribute &quot;nil&quot;)</em>.</p>
  <p>I have no control over what the webservice returns, and the service can provide the xsi:nil attribute to every field in the payload (this is only one of the payloads, other webservices of the same provider use the same convention). As far as I can tell, Jackson 2.12.x should support xsi:nil.
  I would prefer not to change the XML datastructure before parsing it with Jackson, but a simple string concat would even be acceptable if need be.</p>
  <p>Any suggestions on how I can get this working?</p>
  <p><strong>Edit</strong></p>
  <p>I got it <em>working</em> by first doing a string replace of
  <code>&lt;ArrayOfEmployee&gt;</code> to <code>&lt;ArrayOfEmployee xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;</code> and adding a <code>@JsonIgnoreProperties({&quot;nil&quot;})</code> on top of my <code>EmployeeDto</code> class.</p>
  <p>However, I do not like my solution: first, I thought the @JsonIgnoreProperties would no longer be needed, but more importantly, I dislike having to string-replace server payloads before I can parse them. So any more elegant solution is very welcome.</p>
  <p>Thanks</p>