Giter Club home page Giter Club logo

jackson-datatype-protobuf's Introduction

Overview

Jackson module that adds support for serializing and deserializing Google's Protocol Buffers to and from JSON.

Usage

Maven dependency

To use module on Maven-based projects, use following dependency:

<dependency>
  <groupId>com.hubspot.jackson</groupId>
  <artifactId>jackson-datatype-protobuf</artifactId>
  <version><!-- see table below --></version>
</dependency>

Versions

There are separate versions based on which version of Jackson you are using, see the table below:

Jackson 2.7.x Jackson 2.8.x Jackson 2.9.x
0.9.11-jackson2.7 0.9.11-jackson2.8 0.9.11-jackson2.9

Registering module

Registration is done as follows:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new ProtobufModule());

after which functionality is available for all normal Jackson operations.

Interop with Protobuf 3 Canonical JSON Representation

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
  • Any objects don't have any special handling, so the value will be a base64 string, and the type URL field name is typeUrl instead of @type

Protobuf 2 Support

Support has been dropped for com.google.protobuf:protobuf-java:2.x, but you can use an older release if necessary:

  • 0.9.10-jackson2.9-proto2
  • 0.9.10-jackson2.8-proto2
  • 0.9.10-jackson2.7-proto2
  • 0.9.10-preJackson2.7-proto2

Gotchas

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.

jackson-datatype-protobuf's People

Contributors

hs-jenkins-bot avatar jhaber avatar linux-china avatar obotor avatar stevie400 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.