[ https://issues.apache.org/jira/browse/BEAM-6240?focusedWorklogId=182180&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-182180 ]
ASF GitHub Bot logged work on BEAM-6240: ---------------------------------------- Author: ASF GitHub Bot Created on: 08/Jan/19 06:02 Start Date: 08/Jan/19 06:02 Worklog Time Spent: 10m Work Description: reuvenlax commented on pull request #7289: [BEAM-6240] Add a library of schema annotations for POJO and JavaBeans URL: https://github.com/apache/beam/pull/7289#discussion_r245885227 ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ReflectUtils.java ########## @@ -77,6 +82,38 @@ public int hashCode() { }); } + @Nullable + public static Constructor getAnnotatedConstructor(Class clazz) { + return Arrays.stream(clazz.getDeclaredConstructors()) + .filter(m -> Modifier.isPublic(m.getModifiers())) + .filter(m -> m.getAnnotation(SchemaCreate.class) != null) + .findFirst() + .orElse(null); + } + + @Nullable + public static Method getAnnotatedCreateMethod(Class clazz) { + return ANNOTATED_CONSTRUCTORS.computeIfAbsent( + clazz, + c -> { + Method method = + Arrays.stream(clazz.getDeclaredMethods()) + .filter(m -> Modifier.isPublic(m.getModifiers())) + .filter(m -> Modifier.isStatic(m.getModifiers())) + .filter(m -> m.getAnnotation(SchemaCreate.class) != null) + .findFirst() + .orElse(null); + if (method != null && !clazz.isAssignableFrom(method.getReturnType())) { Review comment: same as above. it's a bit weird to have two factory methods, but is there a reason to disallow it? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 182180) Time Spent: 4h 50m (was: 4h 40m) > Allow users to annotate POJOs and JavaBeans for richer functionality > -------------------------------------------------------------------- > > Key: BEAM-6240 > URL: https://issues.apache.org/jira/browse/BEAM-6240 > Project: Beam > Issue Type: Sub-task > Components: sdk-java-core > Reporter: Reuven Lax > Assignee: Reuven Lax > Priority: Major > Time Spent: 4h 50m > Remaining Estimate: 0h > > Desired annotations: > * SchemaIgnore - ignore this field > * FieldName - allow the user to explicitly specify a field name > * SchemaCreate - register a function to be used to create an object (so > fields can be final, and no default constructor need be assumed). -- This message was sent by Atlassian JIRA (v7.6.3#76005)