Skip to content

Commit 9ade1aa

Browse files
timtebeekclaude
andauthored
Fix Jackson 2.21 compatibility for MavenSettings ServerConfiguration parsing (#6605)
* Fix Jackson 2.21 compatibility for MavenSettings ServerConfiguration parsing The issue was that Jackson 2.21 became stricter about matching constructor parameter names with XML property names. The @JacksonXmlProperty(localName = "property") annotation on the httpHeaders field made Jackson think the property name was "property", but the Lombok-generated constructor had a parameter named "httpHeaders", causing a mismatch. The fix: - Use a no-args constructor (marked with @JsonCreator) for ServerConfiguration - Add setters for deserialization - Move Jackson XML annotations from fields to getters - Add explicit @JsonCreator constructor with @JsonProperty annotations to HttpHeader This avoids changing defaultUseWrapper globally, which would require many compensating changes in RawPom and other classes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Further minimize changes * Minimize indentation * Minimize changes and retain immutability --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f60cfb5 commit 9ade1aa

File tree

2 files changed

+473
-459
lines changed

2 files changed

+473
-459
lines changed

rewrite-maven/src/main/java/org/openrewrite/maven/MavenSettings.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.annotation.JsonCreator;
1919
import com.fasterxml.jackson.annotation.JsonIgnore;
2020
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
2122
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
2223
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
2324
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@@ -445,15 +446,12 @@ public static class Server {
445446
ServerConfiguration configuration;
446447
}
447448

448-
@SuppressWarnings("DefaultAnnotationParam")
449-
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
450-
@Data
449+
@EqualsAndHashCode
450+
@FieldDefaults(level = AccessLevel.PRIVATE)
451+
@ToString
451452
@With
452453
@JsonIgnoreProperties("httpHeaders")
453454
public static class ServerConfiguration {
454-
@JacksonXmlProperty(localName = "property")
455-
@JacksonXmlElementWrapper(localName = "httpHeaders", useWrapping = true)
456-
// wrapping is disabled by default on MavenXmlMapper
457455
@Nullable
458456
List<HttpHeader> httpHeaders;
459457

@@ -462,6 +460,26 @@ public static class ServerConfiguration {
462460
*/
463461
@Nullable
464462
Long timeout;
463+
464+
@JsonCreator
465+
public ServerConfiguration() {
466+
}
467+
468+
public ServerConfiguration(@Nullable List<HttpHeader> httpHeaders, @Nullable Long timeout) {
469+
this.httpHeaders = httpHeaders;
470+
this.timeout = timeout;
471+
}
472+
473+
@JacksonXmlProperty(localName = "property")
474+
@JacksonXmlElementWrapper(localName = "httpHeaders", useWrapping = true)
475+
public @Nullable List<HttpHeader> getHttpHeaders() {
476+
return this.httpHeaders;
477+
}
478+
479+
@JacksonXmlProperty(localName = "timeout")
480+
public @Nullable Long getTimeout() {
481+
return this.timeout;
482+
}
465483
}
466484

467485
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)

0 commit comments

Comments
 (0)