use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project CzechIdMng by bcvsolutions.
the class RestTemplateConfig method restTemplate.
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory httpRequestFactory) {
RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
return restTemplate;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project apollo by ctripcorp.
the class CtripMQService method init.
@PostConstruct
public void init() {
restTemplate = new RestTemplate();
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(portalConfig.readTimeout());
rf.setConnectTimeout(portalConfig.connectTimeout());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM));
restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter()));
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project nixmash-blog by mintster.
the class WebConfig method configureMessageConverters.
// endregion
// region Messages
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.registerModule(new JavaTimeModule());
converter.setObjectMapper(objectMapper);
converters.add(converter);
super.configureMessageConverters(converters);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project webanno by webanno.
the class CasToBratJsonTest method testJsonDiff.
@Test
public void testJsonDiff() throws Exception {
String f_base = "src/test/resources/brat_normal.json";
String f_addedMiddle = "src/test/resources/brat_added_entity_near_middle.json";
String f_removedMiddle = "src/test/resources/brat_removed_entity_in_middle.json";
String f_removedEnd = "src/test/resources/brat_removed_entity_near_end.json";
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper mapper = jsonConverter.getObjectMapper();
JsonNode base = mapper.readTree(new File(f_base));
JsonNode addedMiddle = mapper.readTree(new File(f_addedMiddle));
JsonNode removedMiddle = mapper.readTree(new File(f_removedMiddle));
JsonNode removedEnd = mapper.readTree(new File(f_removedEnd));
JsonNode d_addedMiddle = JsonDiff.asJson(base, addedMiddle);
JsonNode d_removedMiddle = JsonDiff.asJson(base, removedMiddle);
JsonNode d_removedEnd = JsonDiff.asJson(base, removedEnd);
System.out.println(d_addedMiddle);
System.out.println(d_removedMiddle);
System.out.println(d_removedEnd);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project webanno by webanno.
the class CasToBratJsonTest method testGenerateBratJsonGetDocument.
/**
* generate brat JSON data for the document
*/
@Test
public void testGenerateBratJsonGetDocument() throws Exception {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
String jsonFilePath = "target/test-output/output_cas_to_json_document.json";
String file = "src/test/resources/tcf04-karin-wl.xml";
CAS cas = JCasFactory.createJCas().getCas();
CollectionReader reader = CollectionReaderFactory.createReader(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, file);
reader.getNext(cas);
JCas jCas = cas.getJCas();
AnnotatorState state = new AnnotatorStateImpl(Mode.ANNOTATION);
state.getPreferences().setWindowSize(10);
state.setFirstVisibleUnit(WebAnnoCasUtil.getFirstSentence(jCas));
state.setProject(project);
VDocument vdoc = new VDocument();
preRenderer.render(vdoc, state, jCas, annotationSchemaService.listAnnotationLayer(project));
GetDocumentResponse response = new GetDocumentResponse();
BratRenderer.render(response, state, vdoc, jCas, annotationSchemaService);
JSONUtil.generatePrettyJson(jsonConverter, response, new File(jsonFilePath));
assertThat(linesOf(new File("src/test/resources/output_cas_to_json_document_expected.json"), "UTF-8")).isEqualTo(linesOf(new File(jsonFilePath), "UTF-8"));
}
Aggregations