Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example for Kotlins inline classes. #823

Merged
merged 1 commit into from
Aug 24, 2020
Merged

Conversation

michael-simons
Copy link
Collaborator

Kotlin provides so called „Inline classes“ (https://kotlinlang.org/docs/reference/inline-classes.html), wrapping standard types into a dedicated type. This makes them a nice fit for IDs etc.

The object mapping process works ootb, the parameter mapping needs some extra work: One has to provide custom serializers for all data classes being used (see IdTypes). Those serializers can be registered with a dedicated SimpleModule. This module needs to be added to the ObjectMapper instance used by OGM to convert parameters:

ObjectMapperFactory.objectMapper()
        .registerModule(KotlinModule())
        .registerModule(IdTypesModule())

The kotlin jackson module may detect them at some point in the future itself (See FasterXML/jackson-module-kotlin#199), but until than that work is necessary.

This closes #822.

Kotlin provides so called „Inline classes“ (https://kotlinlang.org/docs/reference/inline-classes.html), wrapping standard types into a dedicated type. This makes them a nice fit for IDs etc.

The object mapping process works ootb, the parameter mapping needs some extra work: One has to provide custom serializers for all data classes being used (see `IdTypes`). Those serializers can be registered with a dedicated `SimpleModule`. This module needs to be added to the `ObjectMapper` instance used by OGM to convert parameters:

```
ObjectMapperFactory.objectMapper()
        .registerModule(KotlinModule())
        .registerModule(IdTypesModule())
```

The kotlin jackson module may detect them at some point in the future itself (See FasterXML/jackson-module-kotlin#199), but until than that work is necessary.

This closes #822.
@michael-simons michael-simons merged commit 074a815 into 3.2.x Aug 24, 2020
@michael-simons michael-simons deleted the issue/822 branch August 24, 2020 07:02
michael-simons added a commit that referenced this pull request Aug 24, 2020
Kotlin provides so called „Inline classes“ (https://kotlinlang.org/docs/reference/inline-classes.html), wrapping standard types into a dedicated type. This makes them a nice fit for IDs etc.

The object mapping process works ootb, the parameter mapping needs some extra work: One has to provide custom serializers for all data classes being used (see `IdTypes`). Those serializers can be registered with a dedicated `SimpleModule`. This module needs to be added to the `ObjectMapper` instance used by OGM to convert parameters:

```
ObjectMapperFactory.objectMapper()
        .registerModule(KotlinModule())
        .registerModule(IdTypesModule())
```

The kotlin jackson module may detect them at some point in the future itself (See FasterXML/jackson-module-kotlin#199), but until than that work is necessary.

This closes #822.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant