JavaScriptKit icon indicating copy to clipboard operation
JavaScriptKit copied to clipboard

Add an implementation for `JSValueEncoder`

Open MaxDesiatov opened this issue 4 years ago • 5 comments

Do I understand correctly that there's no easy way right now to convert an arbitrary Encodable type to JSValue? We already have JSValueDecoder, but apparently lack the opposite for Encodable...

MaxDesiatov avatar Jan 06 '21 19:01 MaxDesiatov

What all would this entail? I assume an inverse of the decoding method?

jhoughjr avatar Jul 27 '21 15:07 jhoughjr

Yes, I would assume so, but it may need some investigation to confirm this.

MaxDesiatov avatar Jul 29 '21 10:07 MaxDesiatov

Ive discovered a bug it seems that might relate to this issue.

working with Request and Fetch apis. long story short no matter what body I send to my server, JavaScriptKit seems to ensure it is the string literal [object Object] even if I give it my own string literal. Thats not a log output either, its the decode utf8 data on the request at the server.

I tested this by setting body to a JSValue(stringLiteral: ) of the exact json body I wanted. What does my served decode the 15 bytes as [object Object] This is the exact same output as body = body.description info is available for the last few days in the tokamak channel.

So if it cant send the body I tell it to, Encoding won't matter cuz it will just encode the literal string "[object Object]"

jhoughjr avatar Jul 29 '21 18:07 jhoughjr

@kateinoigakukun @j-f1 FYI I have created an implemention of JSValueEncoder. I can make a PR soon – just testing it some more first with some more use-cases.

ephemer avatar Oct 17 '22 15:10 ephemer