In my opinion objectmapper
is not the best option to map protos
since objectmapper
is used to map JSON
into POJO's
and vice versa.
My recomendation for this purpose is using mapstruct
which provides
a wide functionality to map java beans
. Specially between protos
and POJO's
.
Just by creating an interface
mapper for the class
you want to map the framework
generates the implementacion.
I write you an example that you can follow.
import org.mapstruct.Mapper;
@Mapper
public interface EnterpriseProtoMapper {
EnterpriseMessage.Enterprise toProto(Enterprise enterprise);
}
For further information, you can check mapStruct
's documentation in this link:
MapStruct 1.3.1.Final Reference Guide
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…