Hi all, I’m writing a Data Ingestion POC that proc...
# troubleshooting
a
Hi all, I’m writing a Data Ingestion POC that processes a complex POJO. It contain Lists and Maps of other POJO’s, and I’ve stumbled upon the problem of serializing generic types. I’m having a hard time trying to understand how to add TypeHints, or implementing a TypeInfoFactory to annotate the class. I.e.
Copy code
@TypeInfo(MyPojoTypeInfoFactory.class)
public class MyPojo {
  private List<OtherPojo> listOfOtherPojos;
  ...
}
can someone please point me to an example on how to accomplish this? I’m thinking to switch to Avro Serialization because of this, but I’m aware that Kryo must be avoided. Any help will be appreciated. Thank you in advance.
l
Ran across same problem and it took me some time to understand how this should be done. Here's a demonstrative example
Copy code
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TypeInfo(EventTypeFactory.class)
public class State {

    private List<Event> events;

}


public class EventTypeFactory extends TypeInfoFactory<State> {
    @Override
    public TypeInformation<State> createTypeInfo(Type t, Map<String, TypeInformation<?>> genericParameters) {
        return StateTypeInfo.stateInfo;
    }
}


public class StateTypeInfo {

  public static final TypeInformation<Event> eventInfo = Types.POJO(Event.class,
            ImmutableMap.of(
                    "eventId", Types.STRING,
                    // .... more stuff present in Event class
            ));

    
  public static final TypeInformation<State> traceIdStateInfo = Types.POJO(State.class,
            Map.of(
                    "events", Types.LIST(StateTypeInfo.eventInfo),
            )
  );
}
a
Thank you! Looking at it right now.
It worked just fine, thanks again! 🙇
l
np!