diff --git a/docs/Changelog.md b/docs/Changelog.md index 8ee9b236549..09d18de7599 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -61,6 +61,7 @@ * Scenario Activity API implementation * [#6925](https://github.com/TouK/nussknacker/pull/6925) Fix situation when preset labels were presented as `null` when node didn't pass the validation. * [#6935](https://github.com/TouK/nussknacker/pull/6935) Spel: Scenario labels added to meta variable - `#meta.scenarioLabels` +* [#6952](https://github.com/TouK/nussknacker/pull/6952) Improvement: TypeInformation support for scala.Option ## 1.17 diff --git a/docs/MigrationGuide.md b/docs/MigrationGuide.md index 54c8b87808c..0dcbf40e175 100644 --- a/docs/MigrationGuide.md +++ b/docs/MigrationGuide.md @@ -29,6 +29,9 @@ To see the biggest differences please consult the [changelog](Changelog.md). are registered based on class of Serializer instead of instance of Serializer. If you have values that were serialized by these Serializers in some state, the state won't be restored after upgrade. +* [#6952](https://github.com/TouK/nussknacker/pull/6952) Improvement: TypeInformation support for scala.Option: + If you used CaseClassTypeInfoFactory with case classes that contain the Option type, the state won't be restored after the upgrade. + ## In version 1.17.0 ### Code API changes diff --git a/engine/flink/scala-utils/src/main/scala/pl/touk/nussknacker/engine/flink/api/typeinfo/caseclass/CaseClassTypeInfoFactory.scala b/engine/flink/scala-utils/src/main/scala/pl/touk/nussknacker/engine/flink/api/typeinfo/caseclass/CaseClassTypeInfoFactory.scala index 1a920e87752..1b1ac57b791 100644 --- a/engine/flink/scala-utils/src/main/scala/pl/touk/nussknacker/engine/flink/api/typeinfo/caseclass/CaseClassTypeInfoFactory.scala +++ b/engine/flink/scala-utils/src/main/scala/pl/touk/nussknacker/engine/flink/api/typeinfo/caseclass/CaseClassTypeInfoFactory.scala @@ -6,6 +6,7 @@ import org.apache.flink.api.common.typeinfo.{TypeInfoFactory, TypeInformation} import org.apache.flink.api.common.typeutils.TypeSerializer import org.apache.flink.api.java.typeutils.TypeExtractor import org.apache.flink.api.java.typeutils.runtime.NullableSerializer +import pl.touk.nussknacker.engine.flink.api.typeinfo.option.OptionTypeInfo import java.lang.reflect.Type import scala.reflect._ @@ -45,7 +46,13 @@ abstract class CaseClassTypeInfoFactory[T <: Product: ClassTag] extends TypeInfo val fieldNames = fields.map(_.name.decodedName.toString) val fieldTypes = fields.map { field => val fieldClass = mirror.runtimeClass(field.typeSignature) - TypeExtractor.getForClass(fieldClass) + + if (classOf[Option[_]].isAssignableFrom(fieldClass)) { + val optionTypeClass = mirror.runtimeClass(field.typeSignature.typeArgs.head) + new OptionTypeInfo(TypeExtractor.getForClass(optionTypeClass)) + } else { + TypeExtractor.getForClass(fieldClass) + } } (fieldNames, fieldTypes) }