Search code examples
javaserializationprotocol-buffersprotobuf-java

De/Serialzing custom java types with protobuf in java


protocul buffer supports only a close set of types, like int32, strings, repeted, etc.

The problem is that I want to create a custom deserializer for specific things. For example, look at this proto message:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message UberDrive {
  string user_id = 1;
  google.protobuf.Timestamp transaction_timestamp = 2;
  string start_locaion = 3; //WKT data
  string end_locaion = 3; //WKT data
}

Currently, the start_location and end_location just contain WKT data that, later, when needed in the code, is serialized to an org.locationtech.jts.geom.Geometry.class object (which can be a point, linestring, polygon, etc.).

I would like to work directly with the Geometry data type in my pojo to avoid serializing the geometry over and over again and for cleaner code. Is there a way to do that?

I couldn't find any solution for what I was searching for.


Solution

  • No, there is not a way to do that.