private static void validateValueMethod(MethodDescriptor method) { if (method.isStatic()) { throw new IllegalArgumentException("@VersionValue/@JsonValue must not be static"); } if (method.isAbstract()) { throw new IllegalArgumentException("@VersionValue/@JsonValue must not be abstract"); } if (method.getParameterCount() > 0) { throw new IllegalArgumentException("@VersionValue/@JsonValue cannot have parameters"); } if (method.getRawReturnType() == void.class) { throw new IllegalArgumentException("@VersionValue/@JsonValue cannot be void"); } } }
@Override public Optional<ValueType> describe(@Nullable PropertyPath path, TypeContext typeContext, DescribeContext context) { TypeDescriptor type = typeContext.type; MappingResolver mappingResolver = context.getMappingResolver(); MethodDescriptor valueMethod = getValueMethod(type, mappingResolver); if (valueMethod != null) { Class<?> rawDelegateType = valueMethod.getRawReturnType(); StaticExecutable creator = getCreator(type, rawDelegateType, mappingResolver); ValueType valueType = context.describeNow(path, new TypeContext(valueMethod)); return Optional.of(DelegateType.of(valueMethod, creator, valueType)); } return Optional.empty(); }
private void add(MethodDescriptor creatorMethod) { if (creatorMethod.isStatic() && creatorMethod.getRawReturnType() != void.class) { Result<StaticExecutable> creator = context.getMappingResolver().creator(creatorMethod); this.creator = MappingResolver.higherOf(this.creator, creator); } }