package io.junq.examples.usercenter.spring;

import java.util.List;
import java.util.Optional;

import javax.validation.Validator;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;

@Configuration
@ComponentScan({ "io.junq.examples.usercenter.web", "io.junq.examples.common.web" })
@EnableWebMvc
public class UserCenterWebConfiguration extends WebMvcConfigurerAdapter {

	public UserCenterWebConfiguration() {
		super();
	}
	
	public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) {
		final Optional<HttpMessageConverter<?>> converterFound = converters.stream().
				filter(c -> c instanceof AbstractJackson2HttpMessageConverter).findFirst();
		if (converterFound.isPresent()) {
			final AbstractJackson2HttpMessageConverter converter = (AbstractJackson2HttpMessageConverter) converterFound.get();
			converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
			converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
		}
	}
	
	@Bean
	public Validator localValidatorFactoryBean() {
		return new LocalValidatorFactoryBean();
	}
}

@@ -55,20 +55,24 @@
 va.util.
-List
+Iterator
 ;%0Aimport
@@ -82,24 +82,20 @@
 va.util.
-Optional
+List
 ;%0A%0Aimpor
@@ -299,16 +299,59 @@
 ration;%0A
+import org.springframework.http.MediaType;%0A
 import o
@@ -567,24 +567,111 @@
 actoryBean;%0A
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;%0A
 import org.s
@@ -1278,16 +1278,16 @@
 nal 
-Optional
+Iterator
 %3CHtt
@@ -1317,21 +1317,24 @@
 onverter
-Found
+Iterator
  = conve
@@ -1351,14 +1351,15 @@
 am()
-.
 %0A%09%09%09%09
+%09.
 filt
@@ -1421,25 +1421,27 @@
 er).
-findFirst
+iterator
 ();%0A%09%09
-if
+while
  (co
@@ -1451,22 +1451,23 @@
 rter
-Found.isPresen
+Iterator.hasNex
 t())
@@ -1579,16 +1579,20 @@
 rter
-Found.ge
+Iterator.nex
 t();
@@ -1766,16 +1766,834 @@
 %09%7D%0A%09%7D%0A%09%0A
+%09@Override%0A%09public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) %7B%0A%09%09// %E6%96%B9%E6%B3%95%E4%B8%80%EF%BC%9AURL%E5%90%8E%E7%BC%80%0A//%09%09configurer%0A//%09%09%09.favorPathExtension(true)%0A//%09%09%09.favorParameter(false)%0A//%09%09%09.ignoreAcceptHeader(true)%0A//%09%09%09.defaultContentType(MediaType.APPLICATION_JSON);%0A%09%09%0A%09%09// %E6%96%B9%E6%B3%95%E4%BA%8C%EF%BC%9A%E6%9F%A5%E8%AF%A2%E5%8F%82%E6%95%B0%0A//%09%09configurer%0A//%09%09%09.favorPathExtension(false)%0A//%09%09%09.favorParameter(true)%0A//%09%09%09.parameterName(QueryConstants.FORMAT)%0A//%09%09%09.mediaType(QueryConstants.VALUE_JSON, MediaType.APPLICATION_JSON)%0A//%09%09%09.mediaType(QueryConstants.VALUE_XML, MediaType.APPLICATION_XML)%0A//%09%09%09.ignoreAcceptHeader(true)%0A//%09%09%09.defaultContentType(MediaType.APPLICATION_JSON);%0A%09%09%0A%09%09// %E6%96%B9%E6%B3%95%E4%B8%89%EF%BC%9AHeader Accept%E5%AD%97%E6%AE%B5%0A%09%09configurer%0A%09%09%09.favorPathExtension(false)%0A%09%09%09.favorParameter(false)%0A%09%09%09.ignoreAcceptHeader(false)%0A%09%09%09.defaultContentType(MediaType.APPLICATION_JSON);%0A%09%7D%0A%09%0A
 %09@Bean%0A%09

修改默认响应数据类型，pretty print