[ https://issues.apache.org/jira/browse/FLINK-6909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16285999#comment-16285999 ]
ASF GitHub Bot commented on FLINK-6909: --------------------------------------- Github user aljoscha commented on a diff in the pull request: https://github.com/apache/flink/pull/5097#discussion_r156088318 --- Diff: flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java --- @@ -338,4 +340,78 @@ public static boolean hasSuperclass(Class<?> clazz, String superClassName) { } return Object.class; } + + /** + * Count the number of all accessible fields in the current class that are not + * declared static, transient, or final. + */ + public static int countFieldsInClass(Class<?> clazz) { + int fieldCount = 0; + for (Field field : getAllDeclaredFields(clazz, true)) { + if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers()) && + !Modifier.isFinal(field.getModifiers())) { + fieldCount++; + } + } + return fieldCount; + } + + /** + * Returns the declared field with the given name in a class hierarchy. The field might be private. Returns + * null if such a field does not exist. + */ + public static Field getDeclaredField(Class<?> clazz, String name) { + for (Field field : getAllDeclaredFields(clazz, true)) { + if (field.getName().equals(name)) { + return field; + } + } + return null; + } + + /** + * Recursively determine all declared fields that are not static, transient, or final. + * This is required because class.getFields() is not returning fields defined + * in parent classes. + * + * @param clazz class to be analyzed + * @param ignoreDuplicates if true, in case of duplicate field names only the lowest one + * in a hierarchy will be returned; throws an exception otherwise + * @return list of fields + */ + public static List<Field> getAllDeclaredFields(Class<?> clazz, boolean ignoreDuplicates) { + List<Field> result = new ArrayList<>(); + while (clazz != null) { + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers()) || + Modifier.isFinal(field.getModifiers())) { + continue; // we have no use for transient, static, or final fields + } + if (hasFieldWithSameName(field.getName(), result)) { --- End diff -- Isn't this simply `result.stream().anyMatch(f -> f.getName().equals(field.getName()))`? > Flink should support Lombok POJO > -------------------------------- > > Key: FLINK-6909 > URL: https://issues.apache.org/jira/browse/FLINK-6909 > Project: Flink > Issue Type: Wish > Components: Type Serialization System > Reporter: Md Kamaruzzaman > Assignee: Timo Walther > Priority: Minor > > Project lombok helps greatly to reduce boilerplate Java Code. > It seems that Flink does not accept a lombok POJO as a valid pojo. > e.g. Here is a POJO defined with lombok: > @Getter > @Setter > @NoArgsConstructor > public class SimplePojo > Using this Pojo class to read from CSV file throws this exception: > Exception in thread "main" java.lang.ClassCastException: > org.apache.flink.api.java.typeutils.GenericTypeInfo cannot be cast to > org.apache.flink.api.java.typeutils.PojoTypeInfo > It would be great if flink supports lombok POJO. -- This message was sent by Atlassian JIRA (v6.4.14#64029)