flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-6909) Flink should support Lombok POJO
Date Mon, 11 Dec 2017 14:47:03 GMT

    [ https://issues.apache.org/jira/browse/FLINK-6909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16285998#comment-16285998
] 

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_r156090443
  
    --- Diff: flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
---
    @@ -1837,56 +1845,111 @@ private boolean isValidPojoField(Field f, Class<?> clazz,
ArrayList<Type> typeHi
     			Class<?> fieldTypeWrapper = ClassUtils.primitiveToWrapper(f.getType());
     
     			TypeVariable<?> fieldTypeGeneric = null;
    -			if(fieldType instanceof TypeVariable) {
    +			if (fieldType instanceof TypeVariable) {
     				fieldTypeGeneric = (TypeVariable<?>) fieldType;
     				fieldType = materializeTypeVariable(typeHierarchy, (TypeVariable<?>)fieldType);
     			}
    -			for(Method m : clazz.getMethods()) {
    +			for (Method m : clazz.getMethods()) {
     				final String methodNameLow = m.getName().endsWith("_$eq") ?
     						m.getName().toLowerCase().replaceAll("_", "").replaceFirst("\\$eq$", "_\\$eq")
:
     						m.getName().toLowerCase().replaceAll("_", "");
     
     				// check for getter
    -				if(	// The name should be "get<FieldName>" or "<fieldName>" (for scala)
or "is<fieldName>" for boolean fields.
    +				if (	// The name should be "get<FieldName>" or "<fieldName>" (for scala)
or "is<fieldName>" for boolean fields.
     					(methodNameLow.equals("get"+fieldNameLow) || methodNameLow.equals("is"+fieldNameLow)
|| methodNameLow.equals(fieldNameLow)) &&
     					// no arguments for the getter
     					m.getParameterTypes().length == 0 &&
     					// return type is same as field type (or the generic variant of it)
    -					(m.getGenericReturnType().equals( fieldType ) || (fieldTypeWrapper != null &&
m.getReturnType().equals( fieldTypeWrapper )) || (fieldTypeGeneric != null && m.getGenericReturnType().equals(fieldTypeGeneric))
)
    +					(m.getGenericReturnType().equals(fieldType) || (fieldTypeWrapper != null &&
m.getReturnType().equals(fieldTypeWrapper)) || (fieldTypeGeneric != null && m.getGenericReturnType().equals(fieldTypeGeneric)))
     				) {
     					hasGetter = true;
     				}
     				// check for setters (<FieldName>_$eq for scala)
    -				if((methodNameLow.equals("set"+fieldNameLow) || methodNameLow.equals(fieldNameLow+"_$eq"))
&&
    +				if ((methodNameLow.equals("set"+fieldNameLow) || methodNameLow.equals(fieldNameLow+"_$eq"))
&&
     					m.getParameterTypes().length == 1 && // one parameter of the field's type
    -					(m.getGenericParameterTypes()[0].equals( fieldType ) || (fieldTypeWrapper != null
&& m.getParameterTypes()[0].equals( fieldTypeWrapper )) || (fieldTypeGeneric != null
&& m.getGenericParameterTypes()[0].equals(fieldTypeGeneric) ) )&&
    +					(m.getGenericParameterTypes()[0].equals( fieldType ) || (fieldTypeWrapper != null
&& m.getParameterTypes()[0].equals(fieldTypeWrapper)) || (fieldTypeGeneric != null
&& m.getGenericParameterTypes()[0].equals(fieldTypeGeneric)))&&
     					// return type is void.
     					m.getReturnType().equals(Void.TYPE)
     				) {
     					hasSetter = true;
     				}
     			}
     			if(hasGetter && hasSetter) {
    -				return true;
    -			} else {
    -				if(!hasGetter) {
    -					LOG.info(clazz+" does not contain a getter for field "+f.getName() );
    -				}
    -				if(!hasSetter) {
    -					LOG.info(clazz+" does not contain a setter for field "+f.getName() );
    +				return Optional.empty();
    +			} else if (!hasGetter && !hasSetter) {
    +				return Optional.of("No getter and setter found for field " + f.getName());
    +			}
    +			else if(!hasGetter) {
    +				return Optional.of("No getter found for field " + f.getName());
    +			}
    +			else {
    +				return Optional.of("No setter found for field " + f.getName());
    +			}
    +		}
    +	}
    +
    +	/**
    +	 * Returns whether the given class can be instantiated. This requires a public, static,
class
    +	 * with default constructor. Custom serialization logic must not be present.
    +	 *
    +	 * @param clazz class to be analyzed
    +	 * @param allowAbstract if true, allows abstract classes but prints an info to the log
    +	 */
    +	private static Optional<String> checkSerialization(Class<?> clazz, boolean
allowAbstract) {
    --- End diff --
    
    Same as above


> 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)

Mime
View raw message