javalombokprotobuf-java

Build GRPC proto pojo using lombok (or other) to clone java pojo?


I've got a simple java pojo, implemented with Lombok.

I've also got a grpc method that responds with a very similar pojo, but it's implemented as a protobuf.

Is there an easy way for me to create the protobuf pojo from the java pojo, or vice versa, using Lombok or something else?

My simple java pojo is this:

@Data
public class Ez{
  @Column(name = "created_by")
  public String createdBy;

  @Column(name = "value")
  public String value;

  @Column(name = "scope")
  public String scope;
}

and the very similar protobuf object - they differ by one field currently.

  private Ez() {
    createdBy_ = "";
    value_ = "";
  }

etc.

Of course in my app, there's lots more properties on these objects, but for the sake of discussion, this is what I've got. In reality, I've got a list of these that I'd like to convert into an iterable, to add to my response object all at once. If I find nothing else, I'll write a simple conversion method, but it seemed like a common task, possibly, so I thought I'd ask.


Solution

  • As suggested by @Jan Rieke in the comments, MapStruct addresses this.