本文整理汇总了Java中com.fasterxml.jackson.databind.ser.BeanPropertyWriter类的典型用法代码示例。如果您正苦于以下问题:Java BeanPropertyWriter类的具体用法?Java BeanPropertyWriter怎么用?Java BeanPropertyWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanPropertyWriter类属于com.fasterxml.jackson.databind.ser包,在下文中一共展示了BeanPropertyWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MetadataPropertyWriter_serializeAsField_still_works_for_non_Error_objects
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Test
public void MetadataPropertyWriter_serializeAsField_still_works_for_non_Error_objects() throws Exception {
// given
final MetadataPropertyWriter mpw = new MetadataPropertyWriter(mock(BeanPropertyWriter.class));
// when
Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
mpw.serializeAsField(new Object(), mock(JsonGenerator.class), mock(SerializerProvider.class));
}
});
// then
// We expect a NPE because mocking a base BeanPropertyWriter is incredibly difficult and not worth the effort.
assertThat(ex).isInstanceOf(NullPointerException.class);
}
示例2: SmartErrorCodePropertyWriter_serializeAsField_still_works_for_non_Error_objects
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Test
public void SmartErrorCodePropertyWriter_serializeAsField_still_works_for_non_Error_objects() throws Exception {
// given
final SmartErrorCodePropertyWriter secpw = new SmartErrorCodePropertyWriter(mock(BeanPropertyWriter.class));
// when
Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
secpw.serializeAsField(new Object(), mock(JsonGenerator.class), mock(SerializerProvider.class));
}
});
// then
// We expect a NPE because mocking a base BeanPropertyWriter is incredibly difficult and not worth the effort.
assertThat(ex).isInstanceOf(NullPointerException.class);
}
示例3: updateBuilder
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Override
public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescription beanDesc,
BeanSerializerBuilder builder) {
for (BeanPropertyWriter writer : builder.getProperties()) {
JavaType propertyType = writer.getMember().getType();
Class<?> type = propertyType.getRawClass();
List<BeanPropertyDefinition> properties = getProperties(propertyType, config);
Optional.ofNullable(AnnotationUtils.findAnnotation(type, ValueObject.class))//
.filter(it -> properties.size() == 1)//
.flatMap(it -> properties.stream().findFirst())//
.ifPresent(it -> writer.assignSerializer(new PropertyAccessingSerializer(it)));
}
return builder;
}
示例4: JacksonClientModule
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
public JacksonClientModule() {
setSerializerModifier(new BeanSerializerModifier() {
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
List<BeanPropertyWriter> beanProperties) {
for (BeanPropertyWriter writer : beanProperties) {
if (writer.getAnnotation(LinkedResource.class) != null) {
writer.assignSerializer(new LinkedResourceUriSerializer());
}
}
return beanProperties;
}
});
setMixInAnnotation(Resource.class, ResourceMixin.class);
}
示例5: DefaultMethodSkippingModuleProvider
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
public DefaultMethodSkippingModuleProvider() {
module = new SimpleModule();
module.setSerializerModifier(new BeanSerializerModifier() {
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
return super.changeProperties(config, beanDesc, beanProperties.stream().filter(bpw -> {
final AnnotatedMember jacksonMember = bpw.getMember();
final Member member = jacksonMember.getMember();
if (member instanceof Method) {
final Method method = (Method) member;
if (method.isDefault()) {
// only exclude default methods if they are defined on interfaces from the core components
return !method.getDeclaringClass().getName().startsWith(PACKAGE_CORE_COMPONENTS);
}
}
return true;
}).collect(Collectors.toList()));
}
});
}
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:22,代码来源:DefaultMethodSkippingModuleProvider.java
示例6: serializeAsField
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @deprecated Provided for compatibility with deprecated method in Jackson.
*/
@Override
@Deprecated
public void serializeAsField(
final Object pojo,
final JsonGenerator jgen,
final SerializerProvider prov,
final BeanPropertyWriter writer) throws Exception {
if (writer.getAnnotation(LogRedact.class) == null) {
super.serializeAsField(pojo, jgen, prov, writer);
} else { // since 2.3
if (_allowNull && writer.get(pojo) == null) {
super.serializeAsField(pojo, jgen, prov, writer);
} else {
jgen.writeStringField(writer.getSerializedName().getValue(), REDACTION_STRING);
}
}
}
示例7: serializeAsField
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Override
public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider provider, BeanPropertyWriter writer) throws Exception {
if (include(writer)) {
Field[] fields = bean.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
if(field.getType() == Integer.TYPE) {
int value = (int) field.get(bean);
if(value <= 0) {
writer.serializeAsField(bean, jgen, provider);
}
else
super.serializeAsField(bean, jgen, provider, writer);
}
else {
}
}
}
}
示例8: serializeFieldTyped
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
protected void serializeFieldTyped(
Entity entity,
JsonGenerator gen,
SerializerProvider serializers,
BeanDescription beanDescription,
BeanPropertyDefinition beanPropertyDefinition,
TypeSerializer typeSerializer) throws Exception {
try {
if (typeSerializer == null) {
typeSerializer = serializers.findTypeSerializer(serializers.constructType(beanPropertyDefinition.getAccessor().getRawType()));
}
if (typeSerializer == null) {
// if not static type if available use dynamic type if available
Object propertyValue = beanPropertyDefinition.getAccessor().getValue(entity);
if (propertyValue != null) {
typeSerializer = serializers.findTypeSerializer(serializers.constructType(propertyValue.getClass()));
}
}
BeanPropertyWriter bpw = new BeanPropertyWriter(
beanPropertyDefinition,
beanPropertyDefinition.getAccessor(),
beanDescription.getClassAnnotations(),
beanPropertyDefinition.getAccessor().getType(),
null, // will be searched automatically
typeSerializer, // will not be searched automatically
beanPropertyDefinition.getAccessor().getType(),
suppressNulls(serializers.getConfig().getDefaultPropertyInclusion()),
suppressableValue(serializers.getConfig().getDefaultPropertyInclusion()));
bpw.serializeAsField(entity, gen, serializers);
} catch (JsonMappingException ex) {
Logger.getLogger(EntitySerializer.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例9: serialize
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Override
public void serialize(DataMessage value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
Class<?> eventType = value.getEventType();
EventBeanSerializer serializer = (EventBeanSerializer)findSerializer(eventType, provider, true);
BeanPropertyWriter[] props = serializer.getProps();
jgen.writeStartArray();
if (value.isSendScheme())
serializeScheme(eventType, jgen, props);
else
jgen.writeString(eventType.getSimpleName());
jgen.writeStartArray();
for (EventType<?> event : value.getEvents())
for (BeanPropertyWriter prop : props)
if (EVENT_SYMBOL.equals(prop.getName()))
jgen.writeString(value.getSymbolMap().get(event.getEventSymbol()));
else {
Object propValue;
try {
propValue = prop.get(event); // access property via reflection
} catch (Exception e) {
throw new RuntimeException(e);
}
serializeValue(propValue, jgen, provider);
}
jgen.writeEndArray();
jgen.writeEndArray();
}
示例10: serializeScheme
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
private void serializeScheme(Class<?> eventType, JsonGenerator jgen, BeanPropertyWriter[] props)
throws IOException
{
jgen.writeStartArray();
jgen.writeString(eventType.getSimpleName());
jgen.writeStartArray();
for (BeanPropertyWriter prop : props)
jgen.writeString(prop.getName());
jgen.writeEndArray();
jgen.writeEndArray();
}
示例11: findPropWriter
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
protected BeanPropertyWriter findPropWriter(List<BeanPropertyWriter> propWriters, String desiredFieldName) {
for (BeanPropertyWriter propWriter : propWriters) {
if (desiredFieldName.equals(propWriter.getName())) {
return propWriter;
}
}
return null;
}
示例12: ErrorContractSerializationFactory_findPropWriter_returns_null_if_it_cannot_find_
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Test
public void ErrorContractSerializationFactory_findPropWriter_returns_null_if_it_cannot_find_() {
// given
ErrorContractSerializationFactory impl = new ErrorContractSerializationFactory(null, true, true);
// when
BeanPropertyWriter result = impl.findPropWriter(Collections.<BeanPropertyWriter>emptyList(), UUID.randomUUID().toString());
// then
assertThat(result).isNull();
}
示例13: serializeAsField
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Override
public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider provider, BeanPropertyWriter writer)
throws Exception {
if (include(bean, writer)) {
super.serializeAsField(bean, jgen, provider, writer);
}
}
示例14: changeProperties
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
List<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>();
for (BeanPropertyWriter writer : beanProperties) {
boolean readable = isReadable(beanDesc, writer);
if (readable) {
result.add(writer);
}
}
return result;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ConfigurationPropertiesReportEndpoint.java
示例15: isReadable
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; //导入依赖的package包/类
private boolean isReadable(BeanDescription beanDesc, BeanPropertyWriter writer) {
Class<?> parentType = beanDesc.getType().getRawClass();
Class<?> type = writer.getType().getRawClass();
AnnotatedMethod setter = findSetter(beanDesc, writer);
// If there's a setter, we assume it's OK to report on the value,
// similarly, if there's no setter but the package names match, we assume
// that its a nested class used solely for binding to config props, so it
// should be kosher. This filter is not used if there is JSON metadata for
// the property, so it's mainly for user-defined beans.
return (setter != null) || ClassUtils.getPackageName(parentType)
.equals(ClassUtils.getPackageName(type));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ConfigurationPropertiesReportEndpoint.java