use of com.fasterxml.jackson.databind.ser.FilterProvider in project photo-picker-plus-android by chute.
the class MediaModel method serializeImageDataModel.
public String serializeImageDataModel() {
FilterProvider filters = new SimpleFilterProvider().addFilter("imageDataModelFilter", SimpleBeanPropertyFilter.filterOutAllExcept("options", "media"));
String result = null;
try {
result = JsonUtil.getMapper().writer(filters).writeValueAsString(this);
} catch (JsonProcessingException e) {
Log.d(TAG, "", e);
}
return result;
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project jersey by jersey.
the class FilteringJacksonJaxbJsonProvider method writeTo.
@Override
public void writeTo(final Object value, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException {
final FilterProvider filterProvider = provider.get().getFilteringObject(genericType, true, annotations);
if (filterProvider != null) {
ObjectWriterInjector.set(new FilteringObjectWriterModifier(filterProvider, ObjectWriterInjector.getAndClear()));
}
super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders, entityStream);
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project spring-framework by spring-projects.
the class AbstractJackson2HttpMessageConverter method writeInternal.
@Override
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
MediaType contentType = outputMessage.getHeaders().getContentType();
JsonEncoding encoding = getJsonEncoding(contentType);
JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
try {
writePrefix(generator, object);
Class<?> serializationView = null;
FilterProvider filters = null;
Object value = object;
JavaType javaType = null;
if (object instanceof MappingJacksonValue) {
MappingJacksonValue container = (MappingJacksonValue) object;
value = container.getValue();
serializationView = container.getSerializationView();
filters = container.getFilters();
}
if (type != null && value != null && TypeUtils.isAssignable(type, value.getClass())) {
javaType = getJavaType(type, null);
}
ObjectWriter objectWriter;
if (serializationView != null) {
objectWriter = this.objectMapper.writerWithView(serializationView);
} else if (filters != null) {
objectWriter = this.objectMapper.writer(filters);
} else {
objectWriter = this.objectMapper.writer();
}
if (javaType != null && javaType.isContainerType()) {
objectWriter = objectWriter.forType(javaType);
}
SerializationConfig config = objectWriter.getConfig();
if (contentType != null && contentType.isCompatibleWith(MediaType.TEXT_EVENT_STREAM) && config.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
objectWriter = objectWriter.with(this.ssePrettyPrinter);
}
objectWriter.writeValue(generator, value);
writeSuffix(generator, object);
generator.flush();
} catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
}
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project spring-framework by spring-projects.
the class MappingJackson2HttpMessageConverterTests method filters.
@Test
public void filters() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
JacksonFilteredBean bean = new JacksonFilteredBean();
bean.setProperty1("value");
bean.setProperty2("value");
MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
FilterProvider filters = new SimpleFilterProvider().addFilter("myJacksonFilter", SimpleBeanPropertyFilter.serializeAllExcept("property2"));
jacksonValue.setFilters(filters);
this.converter.writeInternal(jacksonValue, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result, containsString("\"property1\":\"value\""));
assertThat(result, not(containsString("\"property2\":\"value\"")));
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project spring-framework by spring-projects.
the class AbstractJackson2View method writeContent.
/**
* 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();
}
Aggregations