Skip to content

Commit

Permalink
Use legacy page serialization mode if no SpringDataWebSettings are pr…
Browse files Browse the repository at this point in the history
…esent.

Fixes GH-3101.
  • Loading branch information
odrotbohm committed May 30, 2024
1 parent 3bc2621 commit d748e86
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.Page;
Expand All @@ -40,8 +39,7 @@
*/
public class SpringDataJacksonConfiguration implements SpringDataJacksonModules {

@Nullable
@Autowired(required = false) SpringDataWebSettings settings;
@Nullable @Autowired(required = false) SpringDataWebSettings settings;

@Bean
public GeoModule jacksonGeoModule() {
Expand Down Expand Up @@ -84,7 +82,7 @@ public PageModule(@Nullable SpringDataWebSettings settings) {

addSerializer(UNPAGED_TYPE, new UnpagedAsInstanceSerializer());

if (settings != null && settings.pageSerializationMode() == PageSerializationMode.DIRECT) {
if (settings == null || settings.pageSerializationMode() == PageSerializationMode.DIRECT) {
setMixInAnnotation(PageImpl.class, WarningMixing.class);
} else {
setMixInAnnotation(PageImpl.class, WrappingMixing.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.web.config;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.web.config.SpringDataJacksonConfiguration.PageModule;
import org.springframework.data.web.config.SpringDataJacksonConfiguration.PageModule.WarningMixing;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Unit tests for {@link SpringDataJacksonConfiguration}.
*
* @author Oliver Drotbohm
*/
class SpringDataJacksonConfigurationUnitTests {

@Test // GH-3101
void usesDirectRenderingIfNoSpringDataWebSettingsArePresent() {

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new PageModule(null));

assertThat(mapper.getSerializationConfig().findMixInClassFor(PageImpl.class)).isEqualTo(WarningMixing.class);
}
}

0 comments on commit d748e86

Please sign in to comment.