Skip to content

Commit

Permalink
Documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoppier committed Jul 12, 2024
1 parent f4afe78 commit bb86795
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
11 changes: 10 additions & 1 deletion website/src/posts/object-mapping/posts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ eleventyNavigation:
order: 12
---

## Ignoring Visibility
By default, only constructors visible from the current scope can be used to called in a mapping.
This can be disabled by adding the following configuration to the `build.gradle.kts` file

```kotlin
mappie {
strictness {
visibility = true // Allow calling constructors not visible from the calling scope
}
}
```

## Using Default Arguments
By default, default arguments are used in implicit mappings. If this is unwanted, this can be disabled by adding
the following configuration tot the `build.gradle.kts` file
```kotlin
mappie {
useDefaultArguments = false // Disable using default arguments in implicit mappings
}
```
4 changes: 2 additions & 2 deletions website/src/posts/object-mapping/posts/explicit.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ All mappings can be defined using `fromExpression`, but to keep the mappings cle
to suggest improvements to your code, `fromProperty` combined with either `via` or `transform` is preferred.

## Handling non-referenceable Targets
We can use the `to` function to refer to construct parameters which do not have a property or to refer to a setter
We can use the `to` function to refer to constructor parameters which do not have a property or to refer to a setter
method.

For example, suppose that we use the same example as above, but `PersonDto.description` does not declare a backing property.
Expand All @@ -93,7 +93,7 @@ data class PersonDto(
description: String,
)
```
We cannot reference `description` via a property reference `to::description`. To target the constructor parameter,
We cannot reference `description` via a property reference `Person::description`. To target the constructor parameter,
we can use `to("description")` to reference the constructor parameter
```kotlin
object PersonMapper : ObjectMappie<Person, PersonDto>() {
Expand Down
8 changes: 6 additions & 2 deletions website/src/posts/object-mapping/posts/multiple-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target parameter. Mappie also supports mapping multiple source parameters to a s
target parameter.

Mappie supports up to five source parameters. This can be achieved via the base classes `ObjectMappie2`,
`ObjectMappie3`, ..., `ObjectMappie5`.
`ObjectMappie3`, ..., `ObjectMappie5`.

For example, suppose we want to map the sources `Person`, `Address`, and `ContactInformation`
to `PersonDto`. We can write this as
Expand All @@ -24,5 +24,9 @@ object PersonDtoMapper : ObjectMappie3<Person, Address, ContactInformation, Pers
}
```

When multiple source parameters are used, and there are multiple properties with the same name in these source
parameters, Mappie will not construct an implicit mapping using either of those properties. This would be an
arbitrary choice, and not transparent.

Note that these multiple source mappers have less built-in functionality, most notable mapping
lists and sets as described in [List & Sets](/object-mapping/lists-and-sets/).
lists and sets as described in [List & Sets](/object-mapping/lists-and-sets/).
2 changes: 1 addition & 1 deletion website/src/posts/object-mapping/posts/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Mappie supports creating object mappers via the base class `ObjectMappie`. Exten
to generate a mapper which will call a constructor and possibly setters of the target type, based on the implicit- and
explicit mappings.

Implicit mappings are resolved are those that can be inferred automatically, and is explained in
Implicit mappings are those that can be inferred automatically, and is explained in
[Inferring Implicit Mappings](/object-mapping/inferring-implicit-mappings/). Explicit mappings need to be defined by
the programmer, for which there are multiple ways: by property, by value, and by expression. These options are
explained in further detail in [Constructing Explicit Mappings](/object-mapping/constructing-explicit-mappings/).
2 changes: 1 addition & 1 deletion website/src/posts/object-mapping/posts/transforming.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ summary: "Transforming source properties using the transform operator."
eleventyNavigation:
key: The Transform Operator
parent: Object Mapping
order: 8
order: 7
---

Mappie can transform source parameters using the operator `transform`. This is useful when we want to change the source
Expand Down
4 changes: 3 additions & 1 deletion website/src/posts/object-mapping/posts/via.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ summary: "Reusing other mappers using the via operator."
eleventyNavigation:
key: The Via Operator
parent: Object Mapping
order: 7
order: 8
---

Mappie has support for reusing mappers in other mappers using the `via` operator.
Expand Down Expand Up @@ -45,5 +45,7 @@ object PersonMapper : ObjectMappie<Person, PersonDto>() {
}
}
```
Do note, that in this case, if `PersonDto::addressDto` was named `PersonDto::address` the mapping does not have to
be defined explicitly. Mappie will construct an implicit mapping using the via operator.

We can also use `via` to map collections. See [List & Sets](/object-mapping/lists-and-sets/).

0 comments on commit bb86795

Please sign in to comment.