https://kotlinlang.org logo
#android
Title
# android
r

ritesh

07/06/2022, 3:40 PM
👋 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

Zach Klippenstein (he/him) [MOD]

07/06/2022, 6:50 PM
Did you mean to tag a different Zach? I know nothing about this library
r

ritesh

07/06/2022, 7:13 PM
Ahh okay. 😂 I meant to tag you! Sorry abt it, though.
g

gildor

07/07/2022, 2:54 AM
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

ritesh

07/07/2022, 6:59 AM
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

gildor

07/08/2022, 3:17 AM
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

ritesh

07/08/2022, 5:19 AM
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

gildor

07/08/2022, 6:58 AM
To do this, message should include field names, isn't it? Or some sort source of those names
r

ritesh

07/08/2022, 7:03 AM
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.
4 Views