Loading Java to Protobuf Converter...
Please wait a moment

How to Convert Java to Protobuf - Step by Step Guide

Step 1

Input Your Java Class Definitions

Start by entering your Java class definitions that need to be converted to Protocol Buffer schema:

•
Paste Java code: Copy class definitions from your Java applications or POJOs
•
Upload Java file: Upload .java files containing class definitions
•
Use sample data: Click "Sample" to load example Java classes and see the conversion

Example: Java Class Input

Here's a typical Java POJO ready for protobuf conversion:

package com.example;

public class User {
    private Integer id;
    private String name;
    private String email;
    private List<String> roles;
    private Boolean active;
    private UserProfile profile;
}

public class UserProfile {
    private String department;
    private Integer experienceYears;
    private List<String> skills;
}
Step 2

Automatic Schema Generation

The tool automatically analyzes your Java classes and generates a corresponding Protocol Buffer schema:

•
Type mapping: Maps Java types to proto3 types (Integer to int32, Long to int64, Boolean to bool, BigDecimal to string so no digits are lost)
•
Field numbering: Assigns sequential field numbers for protobuf schema
•
Nested structures: Inner classes become nested messages and Java enums become proto enums
•
Collection detection: List, Set and arrays become repeated fields, and Map becomes a proto map

Example: Generated Protobuf Schema

The same Java classes, now converted to protobuf schema:

syntax = "proto3";

package com.example;

message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
  repeated string roles = 4;
  bool active = 5;
  UserProfile profile = 6;
}

message UserProfile {
  string department = 1;
  int32 experience_years = 2;
  repeated string skills = 3;
}
Step 3

Copy or Download Protobuf Schema

Once the schema looks right, take it with you:

•
Copy to clipboard: One-click copying for immediate use in your projects
•
Download as .proto: Save as a .proto file for your gRPC services
•
Use it with protoc: Run protoc on the file to generate Java, Go, Python or C# classes for gRPC services

Example: Generated Protobuf Schema

The same Java classes, now converted to protobuf schema:

syntax = "proto3";

package com.example;

message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
  repeated string roles = 4;
  bool active = 5;
  UserProfile profile = 6;
}

message UserProfile {
  string department = 1;
  int32 experience_years = 2;
  repeated string skills = 3;
}

Frequently Asked Questions

Why turn Java classes into a .proto file?

If a Java service already has its data model as POJOs and you are moving to gRPC or sharing data with Go, Python or C# services, writing the .proto by hand is slow and easy to get wrong. Starting from the classes gives you the messages, field types and numbers in one go, and you then tidy up the parts proto3 has no direct form for.

How are Java types mapped?

int, Integer, short and byte become int32; long and Long become int64, so IDs like 8901240544102066246 still fit; float, double and boolean map to float, double and bool; String, char and UUID become string; byte[] becomes bytes. List, Set and arrays become repeated fields, Map<K, V> becomes map<K, V>, and Optional<T> becomes an optional field. BigDecimal and BigInteger become string, because no proto scalar keeps every digit of them, and java.time types become ISO-8601 strings. A comment above the field says when that happened.

What happens to nested classes, enums and records?

Static inner classes become nested messages, Java enums become proto enums (with an _UNSPECIFIED = 0 value first, as proto3 requires, and the enum name as a prefix so two enums never clash), and records are read from their component list. If a class extends another class from the same input, the parent fields are copied in first, since protobuf has no inheritance.

Which fields are left out?

Static and transient fields are skipped because Java serializers skip them too. Methods, constructors, getters and setters, and anything inside comments or string literals are ignored. Interfaces have no fields, so they produce no message.

How are field names and numbers chosen?

camelCase names become snake_case (experienceYears becomes experience_years, userID becomes user_id), and a second field that would end up with the same name gets a _2 suffix. Numbers run from 1 in the order the fields appear. If a field has @JsonProperty or @SerializedName with a different name, that name is kept as json_name so JSON output still matches.

What if my class uses a type that has no proto equivalent?

Lists of lists, maps of lists, maps with enum or object keys, Object, generic type parameters and classes that are not in your input are written as string fields with a comment explaining why. proto3 needs a wrapper message for nested collections, so those comments tell you where to add one. Every schema is checked with a .proto parser before it is shown.

Is my code uploaded anywhere?

No. The conversion runs in your browser and nothing is sent to a server. It reads type declarations only, so it never runs your code.