io.setl.json.spring.CanonicalWebMvcConfigurer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of canonical-json Show documentation
Show all versions of canonical-json Show documentation
An implementation of the Canonical JSON format with support for javax.json and Jackson
The newest version!
package io.setl.json.spring;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Enable JSON input and output.
*
* @author Simon Greatrix on 12/02/2020.
*/
class CanonicalWebMvcConfigurer implements WebMvcConfigurer {
final ObjectMapper mapper;
public CanonicalWebMvcConfigurer(ObjectMapper mapper) {
this.mapper = mapper;
}
@Override
public void extendMessageConverters(List> converters) {
MappingJackson2HttpMessageConverter myConverter = new MappingJackson2HttpMessageConverter(mapper);
int index = -1;
for (int i = 0; i < converters.size(); i++) {
if (converters.get(i) instanceof MappingJackson2HttpMessageConverter) {
index = i;
break;
}
}
if (index == -1) {
converters.add(myConverter);
} else {
converters.set(index, myConverter);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy