// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
[id="extensions-protobuf"]
= 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

ifeval::[{doc-show-badges} == true]
[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native since##[.badge-supported]##1.5.0##
endif::[]

Serialize and deserialize Java objects using Google's Protocol buffers

[id="extensions-protobuf-whats-inside"]
== 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.

[id="extensions-protobuf-maven-coordinates"]
== Maven coordinates

https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-protobuf[Create a new project with this extension on {link-quarkus-code-generator}, 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>
----
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]

[id="extensions-protobuf-additional-camel-quarkus-configuration"]
== Additional Camel Quarkus configuration

[id="extensions-protobuf-configuration-generate-classes-from-protobuf-proto-files"]
=== 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.

[id="extensions-protobuf-configuration-serialize-deserialize-java-beans-using-json-fields-representation"]
=== 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].

