Java Code Examples for org.springframework.http.converter.json.MappingJacksonValue#getFilters()

The following examples show how to use org.springframework.http.converter.json.MappingJacksonValue#getFilters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJackson2View.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Write the actual JSON content to the stream.
 * @param stream the output stream to use
 * @param object the value to be rendered, as returned from {@link #filterModel}
 * @throws IOException if writing failed
 */
protected void writeContent(OutputStream stream, Object object) throws IOException {
	JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding);
	writePrefix(generator, object);

	Object value = object;
	Class<?> serializationView = null;
	FilterProvider filters = null;

	if (value instanceof MappingJacksonValue) {
		MappingJacksonValue container = (MappingJacksonValue) value;
		value = container.getValue();
		serializationView = container.getSerializationView();
		filters = container.getFilters();
	}

	ObjectWriter objectWriter = (serializationView != null ?
			this.objectMapper.writerWithView(serializationView) : this.objectMapper.writer());
	if (filters != null) {
		objectWriter = objectWriter.with(filters);
	}
	objectWriter.writeValue(generator, value);

	writeSuffix(generator, object);
	generator.flush();
}
 
Example 2
Source File: AbstractJackson2View.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Write the actual JSON content to the stream.
 * @param stream the output stream to use
 * @param object the value to be rendered, as returned from {@link #filterModel}
 * @throws IOException if writing failed
 */
protected void writeContent(OutputStream stream, Object object) throws IOException {
	JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding);
	writePrefix(generator, object);

	Object value = object;
	Class<?> serializationView = null;
	FilterProvider filters = null;

	if (value instanceof MappingJacksonValue) {
		MappingJacksonValue container = (MappingJacksonValue) value;
		value = container.getValue();
		serializationView = container.getSerializationView();
		filters = container.getFilters();
	}

	ObjectWriter objectWriter = (serializationView != null ?
			this.objectMapper.writerWithView(serializationView) : this.objectMapper.writer());
	if (filters != null) {
		objectWriter = objectWriter.with(filters);
	}
	objectWriter.writeValue(generator, value);

	writeSuffix(generator, object);
	generator.flush();
}
 
Example 3
Source File: AbstractJackson2View.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write the actual JSON content to the stream.
 * @param stream the output stream to use
 * @param object the value to be rendered, as returned from {@link #filterModel}
 * @throws IOException if writing failed
 */
protected void writeContent(OutputStream stream, Object object) throws IOException {
	JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding);

	writePrefix(generator, object);
	Class<?> serializationView = null;
	FilterProvider filters = null;
	Object value = object;

	if (value instanceof MappingJacksonValue) {
		MappingJacksonValue container = (MappingJacksonValue) value;
		value = container.getValue();
		serializationView = container.getSerializationView();
		filters = container.getFilters();
	}
	if (serializationView != null) {
		this.objectMapper.writerWithView(serializationView).writeValue(generator, value);
	}
	else if (filters != null) {
		this.objectMapper.writer(filters).writeValue(generator, value);
	}
	else {
		this.objectMapper.writeValue(generator, value);
	}
	writeSuffix(generator, object);
	generator.flush();
}
 
Example 4
Source File: AbstractJackson2View.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Write the actual JSON content to the stream.
 * @param stream the output stream to use
 * @param object the value to be rendered, as returned from {@link #filterModel}
 * @throws IOException if writing failed
 */
protected void writeContent(OutputStream stream, Object object)
		throws IOException {

	JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding);

	writePrefix(generator, object);
	Class<?> serializationView = null;
	FilterProvider filters = null;
	Object value = object;

	if (value instanceof MappingJacksonValue) {
		MappingJacksonValue container = (MappingJacksonValue) value;
		value = container.getValue();
		serializationView = container.getSerializationView();
		filters = container.getFilters();
	}
	if (serializationView != null) {
		this.objectMapper.writerWithView(serializationView).writeValue(generator, value);
	}
	else if (filters != null) {
		this.objectMapper.writer(filters).writeValue(generator, value);
	}
	else {
		this.objectMapper.writeValue(generator, value);
	}
	writeSuffix(generator, object);
	generator.flush();
}