Giter VIP home page Giter VIP logo

proto-pojo-generator-maven-plugin's Introduction

proto-pojo-generator-maven-plugin

Pojo and builder code generator.

It will generate pojo and builder code with .proto files. It dependencies on com.baidu:jprotobuf.

usage

<plugin>
    <groupId>com.cloudtogo.plugins</groupId>
    <artifactId>proto-pojo-generator-maven-plugin</artifactId>
    <version>1.0.0</version>
</plugin>

This plugin will find src/resources/proto-pojo.xml, and also you can config your special file like below.

<configuration>
    <config>src/test/resources/proto-pojo-config.xml</config>
</configuration>

proto-pojo.xml example:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <protos>
        <proto>
            <file>src/test/resources/protobuf/helloworld.proto</file>
            <pojo-pkg>com.cloudtogo.helloword.model</pojo-pkg>
        </proto>
    </protos>
</config>

helloworld.proto example:

syntax = "proto3";
package hellword;

service MonitorService {
    rpc Hello (Request) returns (Response);
}

message Request {
    string name = 1;
    bytes content = 2;
}

message Response {
    bytes reply = 1;
}

builder

Usually we have to convert the pojo class to a proto builder, and it's very simple with this plugin.

<proto>
    <file>src/test/resources/protobuf/helloworld.proto</file>
    <pojo-pkg>com.cloudtogo.helloword.model</pojo-pkg>
    <builder-pkg>com.cloudtogo.helloword.builder</builder-pkg>
</proto>

Then RequestBuilder class and ResponseBuilder class will be generated.

Serialize && Deserialize

example:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <protos>
        <proto>
            <file>src/test/resources/protobuf/helloworld.proto</file>
            <pojo-pkg>com.cloudtogo.helloword.model</pojo-pkg>
            <builder-pkg>com.cloudtogo.helloword.builder</builder-pkg>
            <fields>
                <field>
                    <message>Request</message>
                    <field>content</field>
                    <serialize>com.cloudtogo.serializer.Base64JsonSerializer</serialize>
                    <deserialize>com.cloudtogo.deserializer.Base64JsonDeserializer</deserialize>
                </field>
                <field>
                    <message>Response</message>
                    <field>reply</field>
                    <serialize>com.cloudtogo.serializer.Base64JsonSerializer</serialize>
                    <deserialize>com.cloudtogo.deserializer.Base64JsonDeserializer</deserialize>
                </field>
            </fields>
        </proto>
    </protos>
</config>

And the pojo class will like this.

@com.fasterxml.jackson.databind.annotation.JsonSerialize(using = com.cloudtogo.serializer.Base64JsonSerializer.class)
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.cloudtogo.deserializer.Base64JsonDeserializer.class)
private byte[] content;

So you will notice that Serialize && Deserialize only support jackson.

alias

It is too bad if a field name is a key word in java. And you have to rename the field.

example:

<field>
    <message>Request</message>
    <field>name</field>
    <alias>nickname</alias>
</field>

And the pojo class will like this.

private String nickname;

public String getName() {
    return nickname;
}

public void setName(String nickname) {
    this.nickname = nickname;
}

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.