Skip to content

NoSuchMethodError: HateoasProperties.getUseHalAsDefaultJsonMediaType() in Spring Boot 3.5.0-M2 #2954

Closed
@wtell400

Description

@wtell400

Describe the bug

Springdoc's org.springdoc.core.providers.HateoasHalProvider calls HateoasProperties::getUseHalAsDefaultJsonMediaType.

Spring Boot 3.5.0-M2 changed

org.springframework.boot.autoconfigure.hateoas.HateoasProperties.getUseHalAsDefaultJsonMediaType()

to:

org.springframework.boot.autoconfigure.hateoas.HateoasProperties.isUseHalAsDefaultJsonMediaType()

resulting in java.lang.NoSuchMethodError: 'boolean org.springframework.boot.autoconfigure.hateoas.HateoasProperties.getUseHalAsDefaultJsonMediaType()'

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    Spring Boot 3.5.0-M2 + Spring Hateoas 2.5.0-M1
  • What modules and versions of springdoc-openapi are you using?
    Springdoc-openapi 2.8.6

Error occurs on spring contextLoads().

Expected behavior
No runtime.

Additional context
Pull request in Spring Boot: spring-projects/spring-boot#43934

My workaround for now is to explicitly specifiy HateoasHalProvider so that the default bean is not loaded. The workaround overrides isHalEnabled which retrieves the configuration property via @Value.

@Configuration
public class HateoasHalProviderWorkaroundConfiguration {
    @Value("${spring.hateoas.use-hal-as-default-json-media-type:true}")
    private boolean useHalAsDefaultJsonMediaType;

    static class HateoasHalProviderWorkaround extends HateoasHalProvider {
        private final boolean useHalAsDefaultJsonMediaType;

        public HateoasHalProviderWorkaround(Optional<HateoasProperties> hateoasPropertiesOptional, ObjectMapperProvider objectMapperProvider, boolean useHalAsDefaultJsonMediaType) {
            super(hateoasPropertiesOptional, objectMapperProvider);
            this.useHalAsDefaultJsonMediaType = useHalAsDefaultJsonMediaType;
        }

        @Override
        public boolean isHalEnabled() {
            return useHalAsDefaultJsonMediaType;
        }
    }

    @Bean
    HateoasHalProvider hateoasHalProvider(Optional<HateoasProperties> hateoasPropertiesOptional, ObjectMapperProvider objectMapperProvider) {
        return new HateoasHalProviderWorkaround(hateoasPropertiesOptional, objectMapperProvider, useHalAsDefaultJsonMediaType);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions