use of java.beans.ConstructorProperties in project jOOQ by jOOQ.
the class DefaultRecordMapper method init.
private final void init(E instance) {
// Arrays can be mapped easily
if (type.isArray()) {
delegate = new ArrayMapper(instance);
return;
}
if (Stream.class.isAssignableFrom(type)) {
DefaultRecordMapper<R, Object[]> local = new DefaultRecordMapper<>(rowType, Object[].class, configuration);
delegate = r -> (E) Stream.of(local.map(r));
return;
}
// types for convenience
if (type.isPrimitive() || DefaultDataType.types().contains(type) || Enum.class.isAssignableFrom(type)) {
delegate = new ValueTypeMapper();
return;
}
// [#1470] Return a proxy if the supplied type is an interface
if (Modifier.isAbstract(type.getModifiers())) {
delegate = new ProxyMapper();
return;
}
// [#2989] [#2836] Records are mapped
if (AbstractRecord.class.isAssignableFrom(type)) {
delegate = (RecordMapper<R, E>) new RecordToRecordMapper();
return;
}
// [#1340] Allow for using non-public default constructors
try {
delegate = new MutablePOJOMapper(type.getDeclaredConstructor(), instance);
return;
} catch (NoSuchMethodException ignore) {
}
// [#1336] If no default constructor is present, check if there is a
// "matching" constructor with the same number of fields as this record
Constructor<E>[] constructors = (Constructor<E>[]) type.getDeclaredConstructors();
// arguments
for (Constructor<E> constructor : constructors) {
ConstructorProperties properties = constructor.getAnnotation(ConstructorProperties.class);
if (properties != null) {
delegate = new ImmutablePOJOMapperWithConstructorProperties(constructor, properties);
return;
}
}
// argument length
for (Constructor<E> constructor : constructors) {
Class<?>[] parameterTypes = constructor.getParameterTypes();
// Match the first constructor by parameter length
if (parameterTypes.length == fields.length) {
delegate = new ImmutablePOJOMapper(constructor, parameterTypes);
return;
}
}
throw new MappingException("No matching constructor found on type " + type + " for record " + this);
}
use of java.beans.ConstructorProperties in project jackson-databind by FasterXML.
the class Java7SupportImpl method findConstructorName.
@Override
public PropertyName findConstructorName(AnnotatedParameter p) {
AnnotatedWithParams ctor = p.getOwner();
if (ctor != null) {
ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class);
if (props != null) {
String[] names = props.value();
int ix = p.getIndex();
if (ix < names.length) {
return PropertyName.construct(names[ix]);
}
}
}
return null;
}
Aggregations