Hello everyone!!! I need help because I don't know...
# troubleshooting
f
Hello everyone!!! I need help because I don't know if this is the right way to avoid generic types. I need to define a type for HashMap and a List for my POJO object, I did this: First define a class:
Copy code
public class MyHashMapTypeInfoFactory extends TypeInfoFactory<Map<String, InstancePOJO>> {

    @Override
    public TypeInformation<Map<String, InstancePOJO>> createTypeInfo(java.lang.reflect.Type type, Map<String, TypeInformation<?>> map) {
        TypeInformation<Map<String, InstancePOJO>> mapTypeInfo =
                new MapTypeInfo<>(Types.STRING, TypeInformation.of(InstancePOJO.class));

        return mapTypeInfo;
    }
}
And then:
Copy code
public class SampleInstancePOJO implements Serializable{

	

	private static final long serialVersionUID = 1452095855116571750L;

	public String genId;

	@TypeInfo(MyHashMapTypeInfoFactory.class)
	public HashMap<String,InstancePOJO> collectedDataSimple;
When I run my program disabling generic types (env.getConfig().disableGenericTypes();) all works ok, but I don't know if exist a better way. Thanks in advance for any comments Regards Flavio
d
Good question. So this is a very valid approach. If you are looking for something a bit simpler you might want to try using Flink TypeInfo directly in your code something like :
Copy code
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

// assuming you read data and map it to SampleInstancePOJO somehow...
DataStreamString input = ...; // Your input data stream

// Here manually provide type info
TypeInformation<MapString, InstancePOJO> mapTypeInfo = new MapTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, TypeInformation.of(InstancePOJO.class));

DataStreamSampleInstancePOJO pojoStream = input.map(new MapFunctionString, SampleInstancePOJO() {
    @Override
    public SampleInstancePOJO map(String value) throws Exception {
        // your mapping logic here...
        return new SampleInstancePOJO();
    }
}).returns(TypeInformation.of(SampleInstancePOJO.class).createFieldsSerializer(mapTypeInfo));
Try both ways I think and let us know which one is easier for you
f
Thanks Draco for your answer, I going to try this alternative and compare, obviusly your solution is better because is simpler