use of com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder in project jackson-databind by FasterXML.
the class TestBuilderMethods method testSimple.
public void testSimple() {
POJOPropertiesCollector coll = collector(SimpleBuilder.class, "with");
Map<String, POJOPropertyBuilder> props = coll.getPropertyMap();
assertEquals(1, props.size());
POJOPropertyBuilder prop = props.get("x");
assertNotNull(prop);
assertTrue(prop.hasField());
assertFalse(prop.hasGetter());
assertTrue(prop.hasSetter());
}
use of com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder in project swagger-core by swagger-api.
the class ModelResolver method resolveAccessMode.
protected io.swagger.v3.oas.annotations.media.Schema.AccessMode resolveAccessMode(BeanPropertyDefinition propDef, JavaType type, io.swagger.v3.oas.annotations.media.Schema schema) {
if (schema != null && !schema.accessMode().equals(io.swagger.v3.oas.annotations.media.Schema.AccessMode.AUTO)) {
return schema.accessMode();
} else if (schema != null && schema.readOnly()) {
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY;
} else if (schema != null && schema.writeOnly()) {
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.WRITE_ONLY;
}
if (propDef == null) {
return null;
}
JsonProperty.Access access = null;
if (propDef instanceof POJOPropertyBuilder) {
access = ((POJOPropertyBuilder) propDef).findAccess();
}
boolean hasGetter = propDef.hasGetter();
boolean hasSetter = propDef.hasSetter();
boolean hasConstructorParameter = propDef.hasConstructorParameter();
boolean hasField = propDef.hasField();
if (access == null) {
final BeanDescription beanDesc = _mapper.getDeserializationConfig().introspect(type);
List<BeanPropertyDefinition> properties = beanDesc.findProperties();
for (BeanPropertyDefinition prop : properties) {
if (StringUtils.isNotBlank(prop.getInternalName()) && prop.getInternalName().equals(propDef.getInternalName())) {
if (prop instanceof POJOPropertyBuilder) {
access = ((POJOPropertyBuilder) prop).findAccess();
}
hasGetter = hasGetter || prop.hasGetter();
hasSetter = hasSetter || prop.hasSetter();
hasConstructorParameter = hasConstructorParameter || prop.hasConstructorParameter();
hasField = hasField || prop.hasField();
break;
}
}
}
if (access == null) {
if (!hasGetter && !hasField && (hasConstructorParameter || hasSetter)) {
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.WRITE_ONLY;
}
return null;
} else {
switch(access) {
case AUTO:
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.AUTO;
case READ_ONLY:
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY;
case READ_WRITE:
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE;
case WRITE_ONLY:
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.WRITE_ONLY;
default:
return io.swagger.v3.oas.annotations.media.Schema.AccessMode.AUTO;
}
}
}
use of com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder in project requery by requery.
the class DeserializerModifier method updateProperties.
@Override
public List<BeanPropertyDefinition> updateProperties(DeserializationConfig config, BeanDescription beanDesc, List<BeanPropertyDefinition> propDefs) {
List<BeanPropertyDefinition> definitions = super.updateProperties(config, beanDesc, propDefs);
List<BeanPropertyDefinition> remove = new ArrayList<>();
List<BeanPropertyDefinition> add = new ArrayList<>();
for (BeanPropertyDefinition definition : definitions) {
if (definition.hasGetter() && Collection.class.isAssignableFrom(definition.getGetter().getRawType())) {
if (definition instanceof POJOPropertyBuilder) {
POJOPropertyBuilder builder = (POJOPropertyBuilder) definition;
builder = new POJOPropertyBuilder(builder, builder.getFullName()) {
@Override
public boolean hasField() {
// forces the getter to be used on the collection
return false;
}
};
remove.add(definition);
add.add(builder);
}
}
}
definitions.removeAll(remove);
definitions.addAll(add);
return definitions;
}
Aggregations