本文整理汇总了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());
}
示例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();
}
示例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")
));
}
示例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));
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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());
}
}
示例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.");
}
示例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));
*/
}
示例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;
}
示例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;
}
示例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);
}
示例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