question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decode from stream instead of string

See original GitHub issue
class FromString(override val format: StringFormat) : Serializer() {
    override fun <T> fromResponseBody(loader: DeserializationStrategy<T>, body: ResponseBody): T {
      val string = body.string()
      return format.decodeFromString(loader, string)
    }

    override fun <T> toRequestBody(contentType: MediaType, saver: SerializationStrategy<T>, value: T): RequestBody {
      val string = format.encodeToString(saver, value)
      return RequestBody.create(contentType, string)
    }
  }

to

class FromStream(override val format: StringFormat) : Serializer() {
    override fun <T> fromResponseBody(loader: DeserializationStrategy<T>, body: ResponseBody): T {
      val stream = body.byteStream()
      return format.decodeFromStream(loader, stream)
    }

    override fun <T> toRequestBody(contentType: MediaType, saver: SerializationStrategy<T>, value: T): RequestBody {
      val stream = ByteArrayOutputStream()
      format.encodeToStream(saver, value, stream)
      return RequestBody.create(contentType, stream.toByteArray())
    }
  }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
JakeWhartoncommented, Aug 3, 2022

No, nothing has really changed. Streaming still only works for JSON not all text formats. And the APIs this library uses are still marked as unstable which means we cannot upstream it yet.

1reaction
JakeWhartoncommented, Sep 15, 2022

No, the APIs we use are still unstable for any format.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Converting Stream to String and back
I have just tested this and works fine. string test = "Testing 1-2-3"; // convert string to stream byte[] byteArray = Encoding.ASCII.
Read more >
C# Convert String to Stream, and Stream to String
Hi All, i am converting string to stream like this: StreamReader Code = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(refernceCode)));. As my ...
Read more >
Java InputStream to String
In this tutorial, we'll look at how to convert an InputStream to a String. We'll start by using plain Java, including Java8/9 solutions,...
Read more >
io — Core tools for working with streams — Python 3.11.1 ...
The TextIOBase ABC extends IOBase . It deals with streams whose bytes represent text, and handles encoding and decoding to and from strings....
Read more >
3 Ways to Convert Java 8 Stream to an Array - Lambda ...
toArray(String[]::new ) will convert a Stream of String to an array of String ... hence it's toArray() method also return an int[] instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found