当前位置: 首页>>代码示例>>Java>>正文


Java MappingJacksonValue类代码示例

本文整理汇总了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());
}
 
开发者ID:liufeng0103,项目名称:bnade-web-ssh,代码行数:15,代码来源:AuctionServiceTest.java

示例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());
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:19,代码来源:JsonViewConfiguration.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:MappingJackson2JsonView.java

示例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;
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:AbstractJsonpResponseBodyAdvice.java

示例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());
}
 
开发者ID:ssherwood,项目名称:spring-boot-jpa,代码行数:20,代码来源:PageResponseBodyAdvisor.java

示例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);
    }
}
 
开发者ID:gooddata,项目名称:gooddata-java,代码行数:21,代码来源:WarehouseService.java

示例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";
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:8,代码来源:JacksonResponseBodyJsonAdvice.java

示例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;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:18,代码来源:AliyunOssController.java

示例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;
        }
    }
}
 
开发者ID:lemon-china,项目名称:lemon-fileservice,代码行数:31,代码来源:JsonpResponseBodyAdvice.java

示例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");
}
 
开发者ID:swxiao,项目名称:bubble2,代码行数:10,代码来源:ControllerCrossDomainAdvice.java

示例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);
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:13,代码来源:JsonpControllerAdvice.java

示例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 + "(" );
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:MappingJackson2JsonView.java

示例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(");");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:MappingJackson2JsonView.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AbstractJackson2View.java


注:本文中的org.springframework.http.converter.json.MappingJacksonValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。