mirror of https://github.com/halo-dev/halo
Registry PageJacksonSerializer manually
parent
0531dcf1ad
commit
4a6df0bf64
|
@ -1,16 +1,23 @@
|
|||
package cc.ryanc.halo.config;
|
||||
|
||||
import cc.ryanc.halo.config.properties.HaloProperties;
|
||||
import cc.ryanc.halo.security.resolver.AuthenticationArgumentResolver;
|
||||
import cc.ryanc.halo.factory.StringToEnumConverterFactory;
|
||||
import cc.ryanc.halo.security.resolver.AuthenticationArgumentResolver;
|
||||
import cc.ryanc.halo.web.controller.support.PageJacksonSerializer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jackson.JsonComponentModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
|
@ -39,6 +46,20 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
|
|||
@Autowired
|
||||
private HaloProperties haloProperties;
|
||||
|
||||
@Override
|
||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.stream()
|
||||
.filter(c -> c instanceof MappingJackson2HttpMessageConverter)
|
||||
.findFirst().ifPresent(converter -> {
|
||||
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = (MappingJackson2HttpMessageConverter) converter;
|
||||
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
|
||||
JsonComponentModule module = new JsonComponentModule();
|
||||
module.addSerializer(PageImpl.class, new PageJacksonSerializer());
|
||||
ObjectMapper objectMapper = builder.modules(module).build();
|
||||
mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
||||
resolvers.add(new AuthenticationArgumentResolver());
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package cc.ryanc.halo.web.support;
|
||||
package cc.ryanc.halo.web.controller.support;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -14,7 +13,6 @@ import java.io.IOException;
|
|||
* @author johnniang
|
||||
* @date 3/19/19
|
||||
*/
|
||||
@JsonComponent
|
||||
public class PageJacksonSerializer extends JsonSerializer<Page> {
|
||||
|
||||
@Override
|
Loading…
Reference in New Issue