當前位置: 首頁>>代碼示例>>Java>>正文


Java MappingJackson2HttpMessageConverter類代碼示例

本文整理匯總了Java中org.springframework.http.converter.json.MappingJackson2HttpMessageConverter的典型用法代碼示例。如果您正苦於以下問題:Java MappingJackson2HttpMessageConverter類的具體用法?Java MappingJackson2HttpMessageConverter怎麽用?Java MappingJackson2HttpMessageConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MappingJackson2HttpMessageConverter類屬於org.springframework.http.converter.json包,在下文中一共展示了MappingJackson2HttpMessageConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configureMessageConverters

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    /*FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4();
    FastJsonConfig config = new FastJsonConfig();
    config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,//保留空的字段
            SerializerFeature.WriteNullStringAsEmpty,//String null -> ""
            SerializerFeature.WriteNullNumberAsZero);//Number null -> 0
    converter.setFastJsonConfig(config);
    converter.setDefaultCharset(Charset.forName("UTF-8"));*/

    MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
    List<MediaType> mediaTypes = new ArrayList<>();
    mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
    mediaTypes.add(MediaType.TEXT_HTML);
    jacksonConverter.setSupportedMediaTypes(mediaTypes);
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    jacksonConverter.setObjectMapper(objectMapper);
    converters.add(jacksonConverter);
    //converters.add(responseBodyConverter());
}
 
開發者ID:pandboy,項目名稱:pingguopai,代碼行數:22,代碼來源:WebMvcConfigurer.java

示例2: setup

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Before
    public void setup() {
        this.mockMvc = standaloneSetup(new PostController(postService, posts, comments))
            .setCustomArgumentResolvers(
                new PageableHandlerMethodArgumentResolver()
            )
//            .setViewResolvers(new ViewResolver() {
//                @Override
//                public org.springframework.web.servlet.View resolveViewName(String viewName, Locale locale) 
//                    throws Exception {
//                    return new MappingJackson2JsonView(objectMapper);
//                }
//            })
            
            .setMessageConverters(
                new MappingJackson2HttpMessageConverter(objectMapper)
            )

            .alwaysDo(print())
            .apply(springSecurity(springSecurityFilterChain))
            .build();
    }
 
開發者ID:hantsy,項目名稱:spring-microservice-sample,代碼行數:23,代碼來源:ControllerTest.java

示例3: EmailServiceImpl

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
EmailServiceImpl(Environment env,
                 TextService text) {

    this.env     = requireNonNull(env);
    this.text    = requireNonNull(text);
    this.mailgun = new RestTemplate();

    this.mailgun.setMessageConverters(asList(
        new FormHttpMessageConverter(),
        new StringHttpMessageConverter(),
        new MappingJackson2HttpMessageConverter()
    ));

    this.mailgun.getInterceptors().add(new BasicAuthorizationInterceptor(
        "api", env.getProperty("mailgun.apiKey")
    ));
}
 
開發者ID:membaza,項目名稱:users-service,代碼行數:18,代碼來源:EmailServiceImpl.java

示例4: getRestTemplate

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
protected RestTemplate getRestTemplate() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	mapper.registerModule(new Jackson2HalModule());

	MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
	converter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
	converter.setObjectMapper(mapper);

	return new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
}
 
開發者ID:ewolff,項目名稱:microservice-cloudfoundry,代碼行數:12,代碼來源:CatalogClient.java

示例5: postsEndWithPathParam

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Test
public void postsEndWithPathParam() {
  String result = restTemplate.postForObject(
      controllerUrl + "sayhello/{name}",
      null,
      String.class,
      "world");

  assertThat(jsonOf(result, String.class), is("hello world"));

  List<HttpMessageConverter<?>> convertersOld = restTemplate.getMessageConverters();
  List<HttpMessageConverter<?>> converters = new ArrayList<>();
  converters.add(new MappingJackson2HttpMessageConverter());
  restTemplate.setMessageConverters(converters);
  result = restTemplate.postForObject(
      controllerUrl + "sayhello/{name}",
      null,
      String.class,
      "中 國");

  assertThat(result, is("hello 中 國"));
  restTemplate.setMessageConverters(convertersOld);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:24,代碼來源:SpringMvcIntegrationTestBase.java

示例6: main

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
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());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:24,代碼來源:ServiceCenterExample.java

示例7: sendPostForUpload

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
/**
 * 
 * /** sendPostCommand
 *
 * @param url
 * @param parameters
 * @return
 * @throws ClientProtocolException
 */
public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setBufferRequestBody(false);
    
    RestTemplate restTemplate = new RestTemplate(requestFactory);
    List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
    mc.add(new MappingJackson2HttpMessageConverter());
    restTemplate.setMessageConverters(mc);
    
    MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
    postParams.setAll(parameters);
    Map<String, Object> response = new HashMap<String, Object>();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "multipart/form-data");
    headers.set("Accept", "application/json");
    headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue());
    HttpEntity<Object> request = new HttpEntity<Object>(postParams, headers);
    ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
    String body = result.getBody().toString();
    MediaType contentType = result.getHeaders().getContentType();
    HttpStatus statusCode = result.getStatusCode();
    response.put(CONTENT_TYPE, contentType);
    response.put(STATUS_CODE, statusCode);
    response.put(BODY, body);

    return response;

}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:38,代碼來源:RestUtils.java

示例8: ssoFilter

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Bean
public Filter ssoFilter(ClientResources client, String path) {
    MappingJackson2HttpMessageConverter customJsonMessageConverter = new
            MappingJackson2HttpMessageConverter();
    customJsonMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
    MyOAuth2ClientAuthenticationProcessingFilter filter = new MyOAuth2ClientAuthenticationProcessingFilter(path);
    filter.setAllowSessionCreation(true);
    MyOAuth2RestTemplate template = new MyOAuth2RestTemplate(client.getClient(), oauth2ClientContext);
    template.setMessageConverters(Arrays.asList(customJsonMessageConverter));
    filter.setRestTemplate(template);
    MyUserInfoTokenServices tokenServices = new MyUserInfoTokenServices(client.getResource().getUserInfoUri(),
            client.getClient().getClientId(),
            userService,
            userWechatService,
            userPrivilegeService,
            privilegeConfigService);
    tokenServices.setRestTemplate(template);
    filter.setTokenServices(tokenServices);
    return filter;
}
 
開發者ID:luotuo,項目名稱:springboot-security-wechat,代碼行數:21,代碼來源:SecurityConfig.java

示例9: RestTemplate

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
/**
 * Create a new instance of the {@link RestTemplate} using default settings.
 * Default {@link HttpMessageConverter}s are initialized.
 */
@SuppressWarnings("deprecation")
public RestTemplate() {
	this.messageConverters.add(new ByteArrayHttpMessageConverter());
	this.messageConverters.add(new StringHttpMessageConverter());
	this.messageConverters.add(new ResourceHttpMessageConverter());
	this.messageConverters.add(new SourceHttpMessageConverter<Source>());
	this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());

	if (romePresent) {
		this.messageConverters.add(new AtomFeedHttpMessageConverter());
		this.messageConverters.add(new RssChannelHttpMessageConverter());
	}
	if (jaxb2Present) {
		this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
	}
	if (jackson2Present) {
		this.messageConverters.add(new MappingJackson2HttpMessageConverter());
	}
	else if (jacksonPresent) {
		this.messageConverters.add(new org.springframework.http.converter.json.MappingJacksonHttpMessageConverter());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:RestTemplate.java

示例10: testPrepareRestTemplateWithRestTemplateThatMissesJacksonConverter

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Test
public void testPrepareRestTemplateWithRestTemplateThatMissesJacksonConverter() {
	final RestTemplate providedRestTemplate = new RestTemplate();
	final Iterator<HttpMessageConverter<?>> iterator = providedRestTemplate.getMessageConverters().iterator();

	while(iterator.hasNext()){
		if(iterator.next() instanceof MappingJackson2HttpMessageConverter) {
			iterator.remove();
		}
	}

	try {
		DataFlowTemplate.prepareRestTemplate(providedRestTemplate);
	}
	catch(IllegalArgumentException e) {
		assertEquals("The RestTemplate does not contain a required MappingJackson2HttpMessageConverter.", e.getMessage());
		return;
	}

	fail("Expected an IllegalArgumentException to be thrown.");
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:22,代碼來源:DataflowTemplateTests.java

示例11: AbstractZg2proRestTemplate

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
protected AbstractZg2proRestTemplate(SimpleModule sm) {
    super();
    //converters
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new ResourceHttpMessageConverter());
    ObjectMapper jsonMapper = camelToKebabObjectMapper(sm);
    messageConverters.add(new MappingJackson2HttpMessageConverter(jsonMapper));
    this.setMessageConverters(messageConverters);
    //errors handling
    setErrorHandler(new RestTemplateErrorHandler());
    /*
    //interceptors
    LoggingRequestInterceptor lri = new LoggingRequestInterceptor();
    this.setInterceptors(new ArrayList<>());
    this.getInterceptors().add(lri);
    this.setRequestFactory(LoggingRequestFactoryFactory.build(lri));
    */
}
 
開發者ID:zg2pro,項目名稱:spring-rest-basis,代碼行數:22,代碼來源:AbstractZg2proRestTemplate.java

示例12: validateRestTemplate

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
public RestTemplate validateRestTemplate(RestTemplate restTemplate) {
	boolean containsMappingJackson2HttpMessageConverter = false;

	for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) {
		if (converter instanceof MappingJackson2HttpMessageConverter) {
			containsMappingJackson2HttpMessageConverter = true;
		}
	}

	if (!containsMappingJackson2HttpMessageConverter) {
		throw new IllegalArgumentException(
				"The RestTemplate does not contain a required " + "MappingJackson2HttpMessageConverter.");
	}
	return restTemplate;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:16,代碼來源:SkipperClientConfiguration.java

示例13: call

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Override
public RevokedLicenses call() {
    try {
        final String url = REMOTE_ADDRESS + "/ReaderBackend/GetRevokedLicenses";
        RestTemplate restTemplate = new RestTemplate();

        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

        return restTemplate.getForObject(url, RevokedLicenses.class);
    } catch (Exception e) {
        Log.e("MainActivity", e.getMessage(), e);
    }

    return null;
}
 
開發者ID:mDL-ILP,項目名稱:mDL-ILP,代碼行數:16,代碼來源:WebAPI.java

示例14: ableToPostObjectAsJsonWithRequestVariable

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Test
public void ableToPostObjectAsJsonWithRequestVariable() {
  Person input = new Person();
  input.setName("world");

  String result = restTemplate.postForObject(
      controllerUrl + "saysomething?prefix={prefix}",
      jsonRequest(input),
      String.class,
      "hello");

  assertThat(jsonOf(result, String.class), is("hello world"));

  List<HttpMessageConverter<?>> convertersOld = restTemplate.getMessageConverters();
  List<HttpMessageConverter<?>> converters = new ArrayList<>();
  converters.add(new MappingJackson2HttpMessageConverter());
  restTemplate.setMessageConverters(converters);
  input = new Person();
  input.setName("中國");

  result = restTemplate.postForObject(
      controllerUrl + "saysomething?prefix={prefix}",
      jsonRequest(input),
      String.class,
      "hello");

  assertThat(result, is("hello 中國"));
  restTemplate.setMessageConverters(convertersOld);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:30,代碼來源:SpringMvcIntegrationTestBase.java

示例15: createRestTemplate

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; //導入依賴的package包/類
@Bean
public RestTemplate createRestTemplate() {
  RestTemplate restTemplate = new RestTemplate();
  List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
  MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter();
  jsonMessageConverter.setObjectMapper(objectMapper);
  messageConverters.add(jsonMessageConverter);
  restTemplate.setMessageConverters(messageConverters);
  return restTemplate;
}
 
開發者ID:berndruecker,項目名稱:camunda-spring-boot-amqp-microservice-cloud-example,代碼行數:11,代碼來源:RestConfiguration.java


注:本文中的org.springframework.http.converter.json.MappingJackson2HttpMessageConverter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。