:wave: I have a use-case where i need the proto-bu...
# android
r
👋 I have a use-case where i need the proto-buff message to be converted to json at android. More in 🧵
😶 2
There is no support for converting to json from javalite in android. Is there any other way, it can be converted, any other internal tool i am not aware of.
@Zach Klippenstein (he/him) [MOD] Sorry for tagging you in. Would you know if there are further plans to support it, or if there is any alternative solution, which i am not aware of.
z
Did you mean to tag a different Zach? I know nothing about this library
r
Ahh okay. 😂 I meant to tag you! Sorry abt it, though.
g
proto-buff message to be converted to json at android
Can you just deserialise it to data class as protobuf and then use any json library to serialize it back to json?
r
I can, but it wont be scalable for my use-case. I was writing a flipper plugin for it, as flipper doesn't support data-store yet. From client end proto buff messages needs to be sent to the plugin in a readable format, so that it can display in the flipper desktop client. Deserialising to a data class will work for one or two use-cases, but it won't scale well in large code-base.
g
But isn’t to support it you need a way to load proto declarations or classes generated using those proto declarations, there is no way to get names from data itself
r
Yeah, i guess i do now. As there is no support for the conversion to json from proto-java-lite in android. There is a support for proto-java though, it converts protobuff message to json. https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/util/JsonFormat.Printer
g
To do this, message should include field names, isn't it? Or some sort source of those names
r
That's correct which seems to be not there in java-lite version of proto-buff (the light version for android, doesn't contain the names), unlike the java (non-lite) one.
At this point of time, i agree the best shot is to map the message to data-class and then using moshi/gson etc.. convert to json and send.