Java to Protobuf Converter - Generate Protocol Buffer Schema from Java
Turn Java classes, records and enums into a proto3 .proto schema with nested messages, repeated and map fields.
How to Convert Java to Protobuf - Step by Step Guide
Input Your Java Class Definitions
Start by entering your Java class definitions that need to be converted to Protocol Buffer schema:
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; }
Automatic Schema Generation
The tool automatically analyzes your Java classes and generates a corresponding Protocol Buffer schema:
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; }
Copy or Download Protobuf Schema
Once the schema looks right, take it with you:
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.