SpongePowered/Configurate

Kotlin lazy fields

DaRacci opened this issue · 4 comments

When trying to serialise a class containing a lazy value the compiler doesn't allow you to annotate it with @Transient and it seems the objectmapper also doesn't check to ignore them see below.
Screenshot_20220323_231433

Are you able to provide the bytecode for the class in question?

Are you able to provide the bytecode for the class in question?

Here are the classes
https://drive.google.com/drive/folders/1xU5uSVn0acYrjx1G5mrZNksK3lbW1qbs?usp=sharing

  private final kotlin.Lazy localVersion$delegate;
    descriptor: Lkotlin/Lazy;
    flags: (0x0012) ACC_PRIVATE, ACC_FINAL
    RuntimeInvisibleAnnotations:
      0: #113()
        org.jetbrains.annotations.NotNull

  private final kotlin.Lazy localFile$delegate;
    descriptor: Lkotlin/Lazy;
    flags: (0x0012) ACC_PRIVATE, ACC_FINAL
    RuntimeInvisibleAnnotations:
      0: #113()
        org.jetbrains.annotations.NotNull

Not a configurate issue -- the kotlin compiler doesn't seem to mark these fields as synthetic, which should be done for compiler-generated fields. You could maybe add a custom node resolver to the mix that will never return a node for these fields (similar to how NodeResolver.onlyWithSetting() filters out un-annotated fields), but Configurate's behavior here isn't really incorrect.

These bloody delegates have come to bite me in the ass again, supplying something like this also doesn't work, guess I'm going to have to go with your suggestion for the only with settings.
image

image