// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
= Protobuf
:page-aliases: extensions/protobuf.adoc
:linkattrs:
:cq-artifact-id: camel-quarkus-protobuf
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: Serialize and deserialize Java objects using Google's Protocol buffers.
:cq-deprecated: false
:cq-jvm-since: 1.0.0
:cq-native-since: 1.5.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native since##[.badge-supported]##1.5.0##

Serialize and deserialize Java objects using Google's Protocol buffers.

== What's inside

* xref:{cq-camel-components}:dataformats:protobuf-dataformat.adoc[Protobuf data format]

Please refer to the above link for usage and configuration details.

== Maven coordinates

https://code.quarkus.io/?extension-search=camel-quarkus-protobuf[Create a new project with this extension on code.quarkus.io, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-protobuf</artifactId>
</dependency>
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Additional Camel Quarkus configuration

=== Generate classes from protobuf `.proto` files
Use the `generate-code` goal of `quarkus-maven-plugin` to generate Java classes from your `*.proto`
service and message definitions stored in the `src/main/proto` directory:

[source,xml]
----
<build>
    <plugins>
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generate-code</goal>
                        <goal>build</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
----

The https://github.com/apache/camel-quarkus/tree/main/integration-tests/protobuf[camel-quarkus-protobuf integration test] is a good way to learn more.

=== Serialize/Deserialize Java beans using JSON fields representation
Please note that some additional configurations might be needed when using `contentTypeFormat=json`.
Indeed, in such a case, the generated `Builder` class needs to be registered for reflection.

For instance, let's examine the `ProtobufDataFormat` below:

[source,java]
----
ProtobufDataFormat protobufJsonDataFormat = new ProtobufDataFormat(Person.getDefaultInstance(), ProtobufDataFormat.CONTENT_TYPE_FORMAT_JSON);
----

In such a case, the `Person.Builder` class should be xref:user-guide/native-mode.adoc#reflection[registered for reflection], for instance as below:

[source,java]
----
@RegisterForReflection(targets = { org.apache.camel.quarkus.component.protobuf.it.model.AddressBookProtos.Person.Builder.class })
----

A concrete implementation of such a scenario is present in the https://github.com/apache/camel-quarkus/tree/main/integration-tests/protobuf[camel-quarkus-protobuf integration test].

