# mapstruct-spi-protobuf
**Repository Path**: mirrors_GEBIT/mapstruct-spi-protobuf
## Basic Information
- **Project Name**: mapstruct-spi-protobuf
- **Description**: Protobuf accessor naming strategy for Mapstruct
- **Primary Language**: Unknown
- **License**: EUPL-1.2
- **Default Branch**: develop
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-07-05
- **Last Updated**: 2025-11-02
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Mapstruct SPI implementation for protocol buffers [](https://circleci.com/gh/entur/mapstruct-spi-protobuf)
This naming strategy helps [mapstruct](http://mapstruct.org/) generate working mapping code between your domain classes
and protobuf classes. Both [fullblown Java protobuf](https://github.com/protocolbuffers/protobuf/tree/master/java)
and [protolite](https://github.com/protocolbuffers/protobuf/blob/master/java/lite.md) classes suported.
Requires on mapstruct 1.4.0+.
## ProtobufAccessorNamingStrategy
Extends ```DefaultProtobufAccessorNamingStrategy``` and provides necessary information to map all fields automatically *
except*
* oneof
which require manual mapping.
## ProtobufEnumMappingStrategy
Implements ```EnumMappingStrategy``` and provides complete enum constant mappings if you follow Googles style guide for
enums https://developers.google.com/protocol-buffers/docs/style#enums
If needed you can specify a different postfix for the 0 value enum by passing in `mapstructSpi.enumPostfixOverrides` as
a compilerArg in the format of:
`-AmapstructSpi.enumPostfixOverrides=com.package.root.a=POSTFIX_1,com.package.root.b=POSTFIX_2`
Otherwise, this will default to `UNSPECIFIED` as per the Google style guide.
```xml
maven-compiler-pluginno.entur.mapstruct.spiprotobuf-spi-implLATEST.VERSION-AmapstructSpi.enumPostfixOverrides=com.company.name=INVALID
```
## Support - Mapping funcions:
Standard mapping functions between often used proto types and java types:
* Timestamp <-> Instant
* Duration <-> Duration
* Date <-> LocalDate
* TimeOfDay <-> LocalTime
* byte[] <-> ByteString
See [protobuf-support-standard](support-standard) and/or [protobuf-support-lite](support-lite) folders for a
ready-to-use mapstruct mapper.
# Usage
[See example project](usage/)
NB: Make sure you add `collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED` to your mapping interfaces
as protobuf stubs use the builder pattern.
```
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public interface ... {
```
## Maven
NB: Make sure you use the *same version of mapstruct* both in the annotation process and the general dependency.
`mapstruct-spi-protobuf` generally depends on the latest released version of mapstruct.
Add the following section to you maven-compiler-plugin plugin configuration:
```xml
no.entur.mapstruct.spiprotobuf-spi-implLATEST.VERSIONorg.mapstructmapstruct${org.mapstruct.version}
```
Complete example:
```xml
org.apache.maven.pluginsmaven-compiler-plugin1.81.8no.entur.mapstruct.spiprotobuf-spi-implLATEST.VERSIONorg.mapstructmapstruct${org.mapstruct.version}
```
## Gradle
Note: See Maven setup regarding using the same version of mapstruct both in the annotation processor and the general
dependency.
```java
implementation"org.mapstruct:mapstruct:${mapstructVersion}"
annotationProcessor"org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor"no.entur.mapstruct.spi:protobuf-spi-impl:LATEST.VERSION"
```
# More information:
http://mapstruct.org/documentation/stable/reference/html/index.html#using-spi