mcarleio / konvert

This kotlin compiler plugin is using KSP API and generates kotlin code to map one class to another
https://mcarleio.github.io/konvert/
Apache License 2.0
93 stars 8 forks source link

Allow ignoring absent properties #16

Closed shrralis closed 1 year ago

shrralis commented 1 year ago

Is there a way to avoid io.mcarle.konvert.processor.exceptions.PropertyMappingNotExistingException: No property for...?

In my case, there's an Entity with a property with a default value:

data class Entity(
    ...
    var something: Boolean = false,
    ...
)

and a DTO without the field:

data class DTO(
    ...
    // no `something` field
    ...
)

Is there a way to respect the default value declared in the Entity constructor? Having smth like @Konvert(mappings = [Mapping(target = "something", constant = "false")]) seems really redundant

mcarleio commented 1 year ago

Thanks for raising this issue! I am sure it once was possible.

I fixed it and added a unit test, so that it stays like this :)

mcarleio commented 1 year ago

Funny thing: I have just stumbled over my own documentation :laughing:

     * * Your source does not have the information for a target with default value
     *    ```kotlin
     *    @KonvertTo(CarToRepair::class, mappings=[
     *         Mapping(target="defect", ignore=true)
     *    ])
     *    class Car
     *    class CarToRepair(val defect: Boolean = true)
     *    ```

So it was working as expected, I just forgot about that :/