Skip to content

Commit 6da720a

Browse files
committed
Merge branch 'spring-boot-3.5-support' of github.com:mschout/springdoc-openapi into mschout-spring-boot-3.5-support
2 parents 6c3aa8f + 392aec6 commit 6da720a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/providers/HateoasHalProvider.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626

2727
package org.springdoc.core.providers;
2828

29+
import java.util.List;
2930
import java.util.Optional;
3031

3132
import jakarta.annotation.PostConstruct;
3233

3334
import org.springframework.boot.autoconfigure.hateoas.HateoasProperties;
3435
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
36+
import org.springframework.lang.NonNull;
37+
import org.springframework.util.ReflectionUtils;
3538

3639
/**
3740
* The type Hateoas hal provider.
@@ -79,8 +82,26 @@ protected void init() {
7982
*/
8083
public boolean isHalEnabled() {
8184
return hateoasPropertiesOptional
82-
.map(HateoasProperties::getUseHalAsDefaultJsonMediaType)
85+
.map(HateoasHalProvider::isHalEnabled)
8386
.orElse(true);
8487
}
8588

89+
private static boolean isHalEnabled(@NonNull HateoasProperties hateoasProperties) {
90+
// In spring-boot 3.5, the method name was changed from getUseHalAsDefaultJsonMediaType to isUseHalAsDefaultJsonMediaType
91+
var possibleMethodNames = List.of("isUseHalAsDefaultJsonMediaType", "getUseHalAsDefaultJsonMediaType");
92+
93+
for (var methodName : possibleMethodNames) {
94+
var method = ReflectionUtils.findMethod(HateoasProperties.class, methodName);
95+
if (method != null) {
96+
var result = ReflectionUtils.invokeMethod(method, hateoasProperties);
97+
if (result instanceof Boolean halEnabled) {
98+
return halEnabled;
99+
}
100+
101+
throw new IllegalStateException("Method " + methodName + " did not return a boolean value");
102+
}
103+
}
104+
105+
throw new IllegalStateException("No suitable method found to determine if HAL is enabled");
106+
}
86107
}

0 commit comments

Comments
 (0)