Search in sources :

Example 16 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project webanno by webanno.

the class CasToBratJsonTest method testGenerateBratJsonGetCollection.

/**
 * generate BRAT JSON for the collection informations
 *
 * @throws IOException
 *             if an I/O error occurs.
 */
@Test
public void testGenerateBratJsonGetCollection() throws IOException {
    MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    String jsonFilePath = "target/test-output/output_cas_to_json_collection.json";
    GetCollectionInformationResponse collectionInformation = new GetCollectionInformationResponse();
    List<AnnotationLayer> layerList = new ArrayList<>();
    AnnotationLayer layer = new AnnotationLayer();
    layer.setId(1l);
    layer.setDescription("span annoattion");
    layer.setName("pos");
    layer.setType(WebAnnoConst.SPAN_TYPE);
    TagSet tagset = new TagSet();
    tagset.setId(1l);
    tagset.setDescription("pos");
    tagset.setLanguage("de");
    tagset.setName("STTS");
    Tag tag = new Tag();
    tag.setId(1l);
    tag.setDescription("noun");
    tag.setName("NN");
    tag.setTagSet(tagset);
    layerList.add(layer);
    collectionInformation.addCollection("/Collection1/");
    collectionInformation.addCollection("/Collection2/");
    collectionInformation.addCollection("/Collection3/");
    collectionInformation.addDocument("/Collection1/doc1");
    collectionInformation.addDocument("/Collection2/doc1");
    collectionInformation.addDocument("/Collection3/doc1");
    collectionInformation.addDocument("/Collection1/doc2");
    collectionInformation.addDocument("/Collection2/doc2");
    collectionInformation.addDocument("/Collection3/doc2");
    collectionInformation.setSearchConfig(new ArrayList<>());
    List<String> tagSetNames = new ArrayList<>();
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.POS);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.DEPENDENCY);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.NAMEDENTITY);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.COREFERENCE);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.COREFRELTYPE);
    JSONUtil.generatePrettyJson(jsonConverter, collectionInformation, new File(jsonFilePath));
    assertThat(linesOf(new File("src/test/resources/output_cas_to_json_collection_expected.json"), "UTF-8")).isEqualTo(linesOf(new File(jsonFilePath), "UTF-8"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) ArrayList(java.util.ArrayList) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) GetCollectionInformationResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.GetCollectionInformationResponse) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) File(java.io.File) Test(org.junit.Test)

Example 17 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project steve by RWTH-i5-IDSG.

the class GithubReleaseCheckService method init.

@PostConstruct
private void init() {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(API_TIMEOUT_IN_MILLIS);
    factory.setConnectTimeout(API_TIMEOUT_IN_MILLIS);
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy());
    restTemplate = new RestTemplate(Collections.singletonList(new MappingJackson2HttpMessageConverter(mapper)));
    restTemplate.setRequestFactory(factory);
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) PropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PostConstruct(javax.annotation.PostConstruct)

Example 18 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project tutorials by eugenp.

the class WebConfig method configureMessageConverters.

// beans
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
    super.configureMessageConverters(converters);
    converters.add(new MappingJackson2HttpMessageConverter());
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Example 19 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project earth-snow by justlive1.

the class WebConfig method jsonConverter.

@Primary
@Bean
public MappingJackson2HttpMessageConverter jsonConverter() {
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper());
    converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8, MediaType.TEXT_PLAIN));
    return converter;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 20 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project taskana by Taskana.

the class WorkbasketControllerIntTest method getRestTemplate.

/**
 * Return a REST template which is capable of dealing with responses in HAL format
 *
 * @return RestTemplate
 */
private RestTemplate getRestTemplate() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jackson2HalModule());
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
    converter.setObjectMapper(mapper);
    RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
    return template;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2HalModule(org.springframework.hateoas.hal.Jackson2HalModule)

Aggregations

MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)122 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)51 ArrayList (java.util.ArrayList)46 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)38 Test (org.junit.jupiter.api.Test)28 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)25 RestTemplate (org.springframework.web.client.RestTemplate)25 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)20 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)19 HandlerMethod (org.springframework.web.method.HandlerMethod)17 Method (java.lang.reflect.Method)16 Test (org.junit.Test)16 MethodParameter (org.springframework.core.MethodParameter)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Bean (org.springframework.context.annotation.Bean)14 List (java.util.List)9 HttpEntity (org.springframework.http.HttpEntity)7 MediaType (org.springframework.http.MediaType)6 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)6