Facing the exception while trying to convert json ...
# serialization
c
Facing the exception while trying to convert json to protoBuf message using parseFrom() method
com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.
at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1563)
Android Project using protobuf lite plugin
Copy code
try {
    //val stream = assets.open("JsonData.json")
    val jsonString = "{\"platform\":\"chan\"}"
    val chanData = ChanDataProto.ChanData.parseFrom(jsonString.encodeToByteArray())
    Log.d("ChanLog", "Value: ${chanData.platform}")
} catch (ex: Exception) {
    ex.printStackTrace()
}
Proto
Copy code
syntax = "proto3";

package tutorial;

option java_package = "com.chan.chanprotobuf";
option java_outer_classname = "ChanDataProto";

message ChanData {
  string platform = 1;
}
Json
Copy code
{
  "platform": "chan"
}