How do I use `java.util` class like `HashSet` , `A...
# troubleshooting
s
How do I use
java.util
class like
HashSet
,
ArrayList
or
SortedSet
in my POJO without having to use Kyro? The warnings I get when I try this:
Copy code
class java.util.ArrayList does not contain a setter for field size
Class class java.util.ArrayList cannot be used as a POJO type because not all fields are valid POJO fields, and must be processed as GenericType. Please read the Flink documentation on "Data Types & Serialization" for details of the effect on performance and schema evolution.
and
Copy code
No fields were detected for class java.util.HashSet so it cannot be used as a POJO type and must be processed as GenericType. Please read the Flink documentation on "Data Types & Serialization" for details of the effect on performance and schema evolution.
I read through the documentation and stackoverflow and the conclusion is that I need to make a TypeInfoFactory and use it inside a TypeInfo annotation over my POJO. While this seems incredibly tedious since I have a bunch of POJOs in my project, I would be fine with this solution if I could figure out how to do this for the
Set
types I'm using. Any help would be appreciated.
k
Hi @Saleh, I also encountered same issue as far as I have investigated there is no work around rather than implementing type-factory.
s
Hi @Keyur Makwana, Thanks. Do you happen to have an example of a type factory for Sets?
k
Not exactly but you can try replacing list with Set in below code,
Copy code
public class ResourceTypeFactory extends TypeInfoFactory<Log> {
    @Override
    public TypeInformation<Log> createTypeInfo(Type type, Map<String, TypeInformation<?>> map) {
        return Types.POJO(Log.class,ImmutableMap.<String, TypeInformation<?>>builder()
                        .put("resources", Types.LIST(Types.POJO(Resource.class)))
                        .put("version",Types.STRING)
                        .put("user", Types.POJO(User.class))
                .build()
        );
    }
}
s
Sorry, I'm not really sure how to do that. I can't find
SET
in the
Types
package.
k
I have also not much of idea about SET
For the work around you can try by implementing your custom logic and convert SET to List while storing or converting