use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project nikita-noark5-core by HiOA-ABI.
the class AppWebMvcConfiguration method extendMessageConverters.
/**
* Allows us to pretty print JSON/XML output. CLI tools like curl may not prettyprint for you
* so this allows us to format the api output so that any developer testing the system gets nicely
* formatted output.
* However the client should be using Accept: application/json or application/xml when connecting
*/
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
final Optional<HttpMessageConverter<?>> jsonConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2HttpMessageConverter).findFirst();
if (jsonConverterFound.isPresent()) {
final AbstractJackson2HttpMessageConverter converter = (AbstractJackson2HttpMessageConverter) jsonConverterFound.get();
converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
// Convert timestamps to readable text strings
converter.getObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
final Optional<HttpMessageConverter<?>> xmlConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2XmlHttpMessageConverter).findFirst();
if (jsonConverterFound.isPresent()) {
final MappingJackson2XmlHttpMessageConverter converter = (MappingJackson2XmlHttpMessageConverter) xmlConverterFound.get();
converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project paascloud-master by paascloud.
the class PcObjectMapper method buidMvcMessageConverter.
public static void buidMvcMessageConverter(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
ObjectMapper objectMapper = new ObjectMapper().registerModule(new ParameterNamesModule()).registerModule(new Jdk8Module()).registerModule(new JavaTimeModule()).registerModule(simpleModule);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
converters.add(jackson2HttpMessageConverter);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project alf.io by alfio-event.
the class MvcConfiguration method jacksonMessageConverter.
@Bean
public MappingJackson2HttpMessageConverter jacksonMessageConverter() {
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(objectMapper());
return converter;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project incubator-servicecomb-java-chassis by apache.
the class ServiceCenterExample method main.
public static void main(String[] args) throws Exception {
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("X-Tenant-Name", "default");
RequestEntity<String> requestEntity = new RequestEntity<String>(headers, HttpMethod.GET, new URI("http://127.0.0.1:9980/registry/v3/microservices"));
ResponseEntity<String> stringResponseEntity = template.exchange(requestEntity, String.class);
System.out.println(stringResponseEntity.getBody());
ResponseEntity<MicroserviceArray> microseriveResponseEntity = template.exchange(requestEntity, MicroserviceArray.class);
MicroserviceArray microserives = microseriveResponseEntity.getBody();
System.out.println(microserives.getServices().get(1).getServiceId());
// instance
headers.add("X-ConsumerId", microserives.getServices().get(1).getServiceId());
requestEntity = new RequestEntity<String>(headers, HttpMethod.GET, new URI("http://127.0.0.1:9980/registry/v3/microservices/" + microserives.getServices().get(1).getServiceId() + "/instances"));
ResponseEntity<String> microserviceInstanceResponseEntity = template.exchange(requestEntity, String.class);
System.out.println(microserviceInstanceResponseEntity.getBody());
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-cloud-open-service-broker by spring-cloud.
the class NonBindableServiceInstanceBindingControllerIntegrationTest method setUp.
@Before
public void setUp() {
ServiceInstanceBindingService serviceInstanceBindingService = new NonBindableServiceInstanceBindingService();
ServiceInstanceBindingController controller = new ServiceInstanceBindingController(catalogService, serviceInstanceBindingService);
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
}
Aggregations