- Support for value classes in Room entities when using KSP.
- Kotlin code generation (Kotlin CodeGen) can be enabled in Room by adding the room.generateKotlin option to the KSP processor options.
- API for creating a Flow that emits invalidation tracker changes.
- Nullable collection return types are no longer allowed in DAO methods when using Kotlin CodeGen.
- Nullability of type arguments is enforced more strictly when using Kotlin CodeGen, so a Flow of a nullable type must be declared explicitly if null can be emitted.
- Guard against meaningless usage of nullable collections in DAO method return types.
- Abstract properties as DAO getters or DAO queries are disallowed in Kotlin CodeGen and must be rewritten as functions.
From Room
New Features
Supporting value classes in Room for KSP. Room is now able to support value classes in Entities. ( 4194095)
Kotlin code generation(or “Kotlin CodeGen”) can now be enabled in Room ( 4297ec0). To turn on Kotlin CodeGen in Room, add the room.generateKotlin option name to your processor options for KSP. For more details on how to pass processor options for KSP, see the KSP documentation.
Note: When using Kotlin CodeGen, it is important to note that there are additional restrictions that have been added. Abstract properties as DAO getters or DAO queries in Kotlin CodeGen are disallowed, and instead expected to be rewritten as functions to avoid the false notion that the property value is immutable and has a fixed stored result. Another restriction that has been added is that Nullable collection return types are no longer allowed in Room for Kotlin CodeGen.
Warning: You may find that your projects are more strict in terms of nullability when using Kotlin CodeGen. In Kotlin CodeGen, the nullability of type arguments is important, wheras in Java this is mostly ignored. For example, let's say you have a Flow return type and the table is empty. In Java CodeGen, this will not cause any issues, but in Kotlin CodeGen, you will get an error. To avoid this, you will need to use Flow , assuming a null is emitted.
API Changes
Guarding against meaningless usage of nullable collections in DAO method return types. ( I777dc, b/253271782, b/259426907)
Add an API for creating a Flow that emits invalidation tracker changes. The API is useful for creating streams that need to react to database changes. ( I8c790, b/252899305)
Bug Fixes
Disallow abstract properties as DAO getters or DAO queries in Kotlin codegen, instead they should be rewritten as functions to avoid the false notion that the property value is immutable and has a fixed stored result. ( If6a13, b/127483380, b/257967987)