We are in the process of decommissioning this repository. We are moving this code into pragma-engine/platform (see https://github.com/pragmaplatform/pragma-engine/tree/updatePom2023) and will no longer be publishing this artifact to nexus. Once this process is complete, any further changes to this library should be made in pragma-engine/platform/jackson-datatype-protobuf.
https://docs.google.com/document/d/1PhF2tb51l3j-VqnRcLkpmLXPkIHH0jPA6qMe8nSCTVw/edit
This is a fork of the original jackson-datatype-protobuf. A pull request was never merged in, so we forked it to solve issue 76.
Jackson module that adds support for serializing and deserializing Google's Protocol Buffers to and from JSON.
To use module on Maven-based projects, use following dependency:
<dependency>
<groupId>gg.pragma</groupId>
<artifactId>jackson-datatype-protobuf</artifactId>
<version>0.9.13-LongsAsStrings</version>
</dependency>
Registration is done as follows:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new ProtobufModule());
after which functionality is available for all normal Jackson operations.
Protobuf 3 specifies a canonical JSON representation (available here). This library conforms to that representation with a few exceptions:
- int64, fixed64, uint64 are written as JSON numbers instead of strings by default
- ProtobufJacksonConfig now has a field to allow for serialization of these types as strings. See ProtobufJacksonConfig#L8
- This can be set by:
ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new ProtobufModule(ProtobufJacksonConfig.builder().serializeLongsAsStrings(true).build()));
Any
objects don't have any special handling, so the value will be a base64 string, and the type URL field name istypeUrl
instead of@type
This library assumes that field names in proto files will be lowercase with underscores, as is recommended by the protobuf style guide: https://developers.google.com/protocol-buffers/docs/style#message-and-field-names
Use underscore_separated_names for field names – for example, song_name.
If your field names don't match this convention, you may need to set a PropertyNamingStrategy
on your ObjectMapper
for things to work as expected. For example, if your proto field names are camel case, you could configure your ObjectMapper
to use PropertyNamingStrategy.LOWER_CAMEL_CASE
.