In a VS Code context, I'm posting a message to a w...
# javascript
e
In a VS Code context, I'm posting a message to a webview (via
postMessage
). I've noticed that an interface like
Copy code
@JsExport
public interface Report {
  public val rdz: ReportElement?
  ...
}
will have the
rdz
field exposed as a function
rdz
, with an internal object property using an unstable name.
postMessage
will erase all functions, so how am I supposed to access the field?
a
Best option now is to serialize and deserialize your object
e
@andylamax as far as I'm aware functions are not serializable, or are they?
a
functions aren't serializable. But when you serialize your object, you'll get it as a property not as a getter function
e
@andylamax so you're saying stuff like JSON.stringify will transform the getter to a property?
a
hahahaha, I wish. I am saying stuff like
Json.encodeToString
will transform the getter to a propperty Json from
kotlinx.serialization
e
Ahhhhh lol, I wasn't sure about which serialization you were talking about
I've decided to move the processing of the object before the
postMessage
. I'll process it and post a simple JSON object.
a
that too is serialization and it should work
e
Yeah I just didn't want to add another dependency on the Kotlin side
a
thats actually a nice move.
e
Thinking about it, it's also logically better. The less a webview knows/has to process, the better.
But maybe there should be a way to expose fields as object properties instead of getters.