Skip to content

HttpHeader object (= <httpHeaders>) is not wrapped by the XML <property> tag #795

@cmoulliard

Description

@cmoulliard

Issue

The following Maven Settings XML

<settings>
    <servers>
        <server>
            <id>maven-snapshots</id>
            <configuration>
                <httpHeaders>
                    <property>
                        <name>X-JFrog-Art-Api</name>
                        <value>myApiToken</value>
                    </property>
                </httpHeaders>
            </configuration>
        </server>
    </servers>
</settings>

is generated as such as string during jackson serialization

<settings>
   <servers>
       <server>
           <id>maven-snapshots</id>
           <configuration>
               <httpHeaders>
                   <name>X-JFrog-Art-Api</name>
                   <value>myApiToken</value>
               </httpHeaders>
               <timeout>10000</timeout>
           </configuration>
       </server>
   </servers>
</settings>

As you can see the <httpHeaders> is not wrapped with <property />.

The code is available here:

Here is a snapshot of the java class: https://github.com/ch007m/maven-settings-httpheader-issue/blob/main/src/test/java/dev/snowdrop/jackson/httpheader/issue/MavenSettingsSimplified.java

    public static class ServerConfiguration {
        @JacksonXmlProperty(
            localName = "property"
        )
        @JacksonXmlElementWrapper(
            localName = "httpHeaders",
            useWrapping = true
        )
        @JsonIgnore
        private final @Nullable List<HttpHeader> httpHeaders;
        private final @Nullable Long timeout;

        @JsonCreator
        public ServerConfiguration(@JsonProperty("httpHeaders") @Nullable List<HttpHeader> httpHeaders, @JsonProperty("timeout") @Nullable Long timeout) {
            this.httpHeaders = httpHeaders;
            this.timeout = timeout;
        }

        public @Nullable List<HttpHeader> getHttpHeaders() {
            return this.httpHeaders;
        }

        public @Nullable Long getTimeout() {
            return this.timeout;
        }

        public ServerConfiguration withHttpHeaders(final @Nullable List<HttpHeader> httpHeaders) {
            return this.httpHeaders == httpHeaders ? this : new ServerConfiguration(httpHeaders, this.timeout);
        }

        public ServerConfiguration withTimeout(final @Nullable Long timeout) {
            return this.timeout == timeout ? this : new ServerConfiguration(this.httpHeaders, timeout);
        }
    }

    public static class HttpHeader {
        private final String name;
        private final String value;

        @JsonCreator
        public HttpHeader(@JsonProperty("name") String name, @JsonProperty("value") String value) {
            this.name = name;
            this.value = value;
        }

        public String getName() {
            return this.name;
        }

        public String getValue() {
            return this.value;
        }

        public HttpHeader withName(final String name) {
            return this.name == name ? this : new HttpHeader(name, this.value);
        }

        public HttpHeader withValue(final String value) {
            return this.value == value ? this : new HttpHeader(this.name, value);
        }
    }

Test method which is failing is: https://github.com/ch007m/maven-settings-httpheader-issue/blob/main/src/test/java/dev/snowdrop/jackson/httpheader/issue/SimpleSettingsXmlTest.java#L74

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions