本文整理汇总了Java中org.springframework.http.converter.json.MappingJacksonValue类的典型用法代码示例。如果您正苦于以下问题:Java MappingJacksonValue类的具体用法?Java MappingJacksonValue怎么用?Java MappingJacksonValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MappingJacksonValue类属于org.springframework.http.converter.json包,在下文中一共展示了MappingJacksonValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAllTest2
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Test
public void findAllTest2() throws Exception {
Auction auction = new Auction();
auction.setRealmId(1);
auction.setItemId(124105);
List<Auction> auctions = auctionService.findAll(auction);
ObjectMapper mapper = new ObjectMapper();
FilterProvider filters = new SimpleFilterProvider().addFilter("auctionFilter",
SimpleBeanPropertyFilter.filterOutAllExcept("owner"));
MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(auctions);
mappingJacksonValue.setFilters(filters);
System.out.println(mappingJacksonValue.getValue());
}
示例2: beforeBodyWriteInternal
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void beforeBodyWriteInternal(final MappingJacksonValue bodyContainer,
final MediaType contentType,
final MethodParameter returnType,
final ServerHttpRequest request,
final ServerHttpResponse response) {
final Mutable<Class<?>> viewClass = Mutable.of(View.Anonymous.class);
if (SecurityContextHolder.getContext().getAuthentication() != null && SecurityContextHolder.getContext().getAuthentication().getAuthorities() != null) {
final Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities();
viewClass.mutateIf(View.User.class, authorities.stream().anyMatch(o -> o.getAuthority().equals("PRIV_USER")));
viewClass.mutateIf(View.Moderator.class, authorities.stream().anyMatch(o -> o.getAuthority().equals("PRIV_MODERATOR")));
viewClass.mutateIf(View.Admin.class, authorities.stream().anyMatch(o -> o.getAuthority().equals("PRIV_ADMIN")));
}
bodyContainer.setSerializationView(viewClass.get());
}
示例3: filterAndWrapModel
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected Object filterAndWrapModel(Map<String, Object> model, HttpServletRequest request) {
Object value = super.filterAndWrapModel(model, request);
String jsonpParameterValue = getJsonpParameterValue(request);
if (jsonpParameterValue != null) {
if (value instanceof MappingJacksonValue) {
((MappingJacksonValue) value).setJsonpFunction(jsonpParameterValue);
}
else {
MappingJacksonValue container = new MappingJacksonValue(value);
container.setJsonpFunction(jsonpParameterValue);
value = container;
}
}
return value;
}
示例4: beforeBodyWriteInternal
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
for (String name : this.jsonpQueryParamNames) {
String value = servletRequest.getParameter(name);
if (value != null) {
if (!isValidJsonpQueryParam(value)) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring invalid jsonp parameter value: " + value);
}
continue;
}
MediaType contentTypeToUse = getContentType(contentType, request, response);
response.getHeaders().setContentType(contentTypeToUse);
bodyContainer.setJsonpFunction(value);
break;
}
}
}
示例5: jsonView
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Test
public void jsonView() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
JacksonViewBean bean = new JacksonViewBean();
bean.setWithView1("with");
bean.setWithView2("with");
bean.setWithoutView("without");
MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
jacksonValue.setSerializationView(MyJacksonView1.class);
this.writeInternal(jacksonValue, outputMessage);
String result = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
assertThat(result, containsString("<withView1>with</withView1>"));
assertThat(result, not(containsString("<withView2>with</withView2>")));
assertThat(result, not(containsString("<withoutView>without</withoutView>")));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:MappingJackson2XmlHttpMessageConverterTests.java
示例6: beforeBodyWriteInternal
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer,
MediaType contentType, MethodParameter returnType,
ServerHttpRequest request, ServerHttpResponse response) {
Page<?> page = ((Page<?>) bodyContainer.getValue());
response.getHeaders().add(CUSTOM_HEADER_META_PAGINATION,
String.format(PAGE_METADATA_FMT, page.getNumber(), page.getSize(),
page.getTotalElements(), page.getTotalPages(), page.isFirst(),
page.isLast()));
getHttpHeaderLinksString(request, page)
.filter(StringUtils::isNotEmpty)
.ifPresent(s -> response.getHeaders().add(HttpHeaders.LINK, s));
// finally, strip out the actual content and replace it as the body value
bodyContainer.setValue(page.getContent());
}
示例7: createWarehouseTask
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
private WarehouseTask createWarehouseTask(final String targetUri,
final HttpMethod httpMethod,
final WarehouseS3Credentials s3Credentials,
final HttpEntity<MappingJacksonValue> requestEntity,
final Object... args) {
try {
final HttpEntity<WarehouseTask> taskHttpEntity = restTemplate.exchange(targetUri, httpMethod,
requestEntity, WarehouseTask.class, args);
if (taskHttpEntity == null || taskHttpEntity.getBody() == null) {
throw new WarehouseS3CredentialsException(targetUri,
format("Empty response when trying to %s S3 credentials via API", httpMethod.name()));
}
return taskHttpEntity.getBody();
} catch (GoodDataException | RestClientException e) {
final String expandedTargetUri = new UriTemplate(targetUri).expand(args).toString();
throw new WarehouseS3CredentialsException(targetUri, format("Unable to %s S3 credentials %s with region: %s, access key: %s",
httpMethod.name(), expandedTargetUri, s3Credentials.getRegion(), s3Credentials.getAccessKey()), e);
}
}
示例8: beforeBodyWriteInternal
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
MethodParameter returnType, ServerHttpRequest request,
ServerHttpResponse response) {
((ResponseBodyMessage) bodyContainer.getValue()).businessMsg = "xxxxxxxxxxxxxx";
}
示例9: policy
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
/**
* 签名生成
* @param callback 跨域请求
* @return
*/
@GetMapping("/policy")
@ResponseBody
//@CrossOrigin(origins = "*", methods = RequestMethod.GET) // 该注解不支持JDK1.7
public Object policy(@RequestParam(required = false) String callback) {
JSONObject result = aliyunOssService.policy();
if (StringUtils.isBlank(callback)) {
return result;
}
MappingJacksonValue jsonp = new MappingJacksonValue(result);
jsonp.setJsonpFunction(callback);
return jsonp;
}
示例10: beforeBodyWriteInternal
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
/**
* 重写callback方法,使即支持jsonp格式也支持json格式
*/
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
//如果不存在callback这个请求参数,直接返回,不需要处理为jsonp
if (ObjectUtils.isEmpty(servletRequest.getParameter("callback"))) {
return;
}
//按设定的请求参数(JsonAdvice构造方法中的this.jsonpQueryParamNames = new String[]{"callback"};),处理返回结果为jsonp格式
for (String name : this.jsonpQueryParamNames) {
String value = servletRequest.getParameter(name);
if (value != null) {
if (!isValidJsonpQueryParam(value)) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring invalid jsonp parameter value: " + value);
}
continue;
}
MediaType contentTypeToUse = getContentType(contentType, request, response);
response.getHeaders().setContentType(contentTypeToUse);
bodyContainer.setJsonpFunction(value);
return;
}
}
}
示例11: beforeBodyWriteInternal
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType,
ServerHttpRequest request, ServerHttpResponse response) {
response.getHeaders().set("Access-Control-Allow-Headers",
"Origin,No-Cache,X-Requested-with,If-Modified-Since,Last-Modified,Cache-Control,Expires,Content-Type");
response.getHeaders().set("Access-Control-Allow-Origin", "*");
response.getHeaders().set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE");
response.getHeaders().set("Access-Control-Max-Age", "1512000");
}
示例12: beforeBodyWriteInternal
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void beforeBodyWriteInternal(final MappingJacksonValue bodyContainer,
final MediaType contentType,
final MethodParameter returnType,
final ServerHttpRequest request,
final ServerHttpResponse response) {
final HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
if (isGET(servletRequest) && isJsonpURI(servletRequest)) {
super.beforeBodyWriteInternal(bodyContainer, contentType, returnType, request, response);
}
}
示例13: writePrefix
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void writePrefix(JsonGenerator generator, Object object) throws IOException {
if (this.jsonPrefix != null) {
generator.writeRaw(this.jsonPrefix);
}
String jsonpFunction = null;
if (object instanceof MappingJacksonValue) {
jsonpFunction = ((MappingJacksonValue) object).getJsonpFunction();
}
if (jsonpFunction != null) {
generator.writeRaw("/**/");
generator.writeRaw(jsonpFunction + "(" );
}
}
示例14: writeSuffix
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
@Override
protected void writeSuffix(JsonGenerator generator, Object object) throws IOException {
String jsonpFunction = null;
if (object instanceof MappingJacksonValue) {
jsonpFunction = ((MappingJacksonValue) object).getJsonpFunction();
}
if (jsonpFunction != null) {
generator.writeRaw(");");
}
}
示例15: filterAndWrapModel
import org.springframework.http.converter.json.MappingJacksonValue; //导入依赖的package包/类
/**
* Filter and optionally wrap the model in {@link MappingJacksonValue} container.
* @param model the model, as passed on to {@link #renderMergedOutputModel}
* @param request current HTTP request
* @return the wrapped or unwrapped value to be rendered
*/
protected Object filterAndWrapModel(Map<String, Object> model, HttpServletRequest request) {
Object value = filterModel(model);
Class<?> serializationView = (Class<?>) model.get(JsonView.class.getName());
FilterProvider filters = (FilterProvider) model.get(FilterProvider.class.getName());
if (serializationView != null || filters != null) {
MappingJacksonValue container = new MappingJacksonValue(value);
container.setSerializationView(serializationView);
container.setFilters(filters);
value = container;
}
return value;
}