use of com.fasterxml.jackson.databind.ser.BeanPropertyWriter in project eureka by Netflix.
the class AbstractEurekaJacksonCodec method bindAmazonInfoFilter.
private void bindAmazonInfoFilter(ObjectMapper mapper) {
SimpleFilterProvider filters = new SimpleFilterProvider();
final String filterName = "exclude-amazon-info-entries";
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
@Override
public Object findFilterId(Annotated a) {
if (Map.class.isAssignableFrom(a.getRawType())) {
return filterName;
}
return super.findFilterId(a);
}
});
filters.addFilter(filterName, new SimpleBeanPropertyFilter() {
@Override
protected boolean include(BeanPropertyWriter writer) {
return true;
}
@Override
protected boolean include(PropertyWriter writer) {
return MINI_AMAZON_INFO_INCLUDE_KEYS.contains(writer.getName());
}
});
mapper.setFilters(filters);
}
use of com.fasterxml.jackson.databind.ser.BeanPropertyWriter in project jackson-databind by FasterXML.
the class BeanAsArraySerializer method serializeAsArray.
protected final void serializeAsArray(Object bean, JsonGenerator gen, SerializerProvider provider) throws IOException {
final BeanPropertyWriter[] props;
if (_filteredProps != null && provider.getActiveView() != null) {
props = _filteredProps;
} else {
props = _props;
}
int i = 0;
try {
for (final int len = props.length; i < len; ++i) {
BeanPropertyWriter prop = props[i];
if (prop == null) {
// can have nulls in filtered list; but if so, MUST write placeholders
gen.writeNull();
} else {
prop.serializeAsElement(bean, gen, provider);
}
}
// NOTE: any getters can not be supported either
//if (_anyGetterWriter != null) {
// _anyGetterWriter.getAndSerialize(bean, gen, provider);
//}
} catch (Exception e) {
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
wrapAndThrow(provider, e, bean, name);
} catch (StackOverflowError e) {
JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
mapE.prependPath(new JsonMappingException.Reference(bean, name));
throw mapE;
}
}
use of com.fasterxml.jackson.databind.ser.BeanPropertyWriter in project jackson-databind by FasterXML.
the class JacksonAnnotationIntrospector method findAndAddVirtualProperties.
@Override
public void findAndAddVirtualProperties(MapperConfig<?> config, AnnotatedClass ac, List<BeanPropertyWriter> properties) {
JsonAppend ann = _findAnnotation(ac, JsonAppend.class);
if (ann == null) {
return;
}
final boolean prepend = ann.prepend();
JavaType propType = null;
// First: any attribute-backed properties?
JsonAppend.Attr[] attrs = ann.attrs();
for (int i = 0, len = attrs.length; i < len; ++i) {
if (propType == null) {
propType = config.constructType(Object.class);
}
BeanPropertyWriter bpw = _constructVirtualProperty(attrs[i], config, ac, propType);
if (prepend) {
properties.add(i, bpw);
} else {
properties.add(bpw);
}
}
// Then: general-purpose virtual properties?
JsonAppend.Prop[] props = ann.props();
for (int i = 0, len = props.length; i < len; ++i) {
BeanPropertyWriter bpw = _constructVirtualProperty(props[i], config, ac);
if (prepend) {
properties.add(i, bpw);
} else {
properties.add(bpw);
}
}
}
use of com.fasterxml.jackson.databind.ser.BeanPropertyWriter in project jackson-module-afterburner by FasterXML.
the class TestAccessorGeneration method testLotsaIntAccessorGeneration.
// And then test to ensure Switch-table construction also works...
public void testLotsaIntAccessorGeneration() throws Exception {
PropertyAccessorCollector coll = new PropertyAccessorCollector(BeanN.class);
String[] methodNames = new String[] { "getX", "getY", "get3", "get4", "get5", "get6", "get7" };
for (String methodName : methodNames) {
Method method = BeanN.class.getDeclaredMethod(methodName);
AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null);
coll.addIntGetter(new BeanPropertyWriter(SimpleBeanPropertyDefinition.construct(null, annMethod, new PropertyName(methodName)), annMethod, null, null, null, null, null, false, null));
}
BeanPropertyAccessor acc = coll.findAccessor(null);
BeanN bean = new BeanN();
assertEquals(bean.getX(), acc.intGetter(bean, 0));
assertEquals(bean.getY(), acc.intGetter(bean, 1));
assertEquals(bean.get3(), acc.intGetter(bean, 2));
assertEquals(bean.get4(), acc.intGetter(bean, 3));
assertEquals(bean.get5(), acc.intGetter(bean, 4));
assertEquals(bean.get6(), acc.intGetter(bean, 5));
assertEquals(bean.get7(), acc.intGetter(bean, 6));
}
use of com.fasterxml.jackson.databind.ser.BeanPropertyWriter in project Rosetta by HubSpot.
the class StoredAsJsonBeanSerializerModifier method changeProperties.
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
for (BeanPropertyWriter beanProperty : beanProperties) {
StoredAsJson storedAsJson = beanProperty.getAnnotation(StoredAsJson.class);
if (storedAsJson != null && !StoredAsJson.NULL.equals(storedAsJson.empty())) {
final JsonSerializer<Object> nullSerializer;
if (storedAsJson.binary()) {
nullSerializer = new ConstantBinarySerializer(storedAsJson.empty());
} else {
nullSerializer = new ConstantSerializer(storedAsJson.empty());
}
beanProperty.assignNullSerializer(nullSerializer);
}
}
return super.changeProperties(config, beanDesc, beanProperties);
}
Aggregations