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.

Allow setting headers from Serializer

See original GitHub issue

Existing API (which I suppose was modeled after java API) have immutable Headers as an argument to serialize:

def serialize(topic: String, headers: Headers, a: A): F[Array[Byte]]

Immutability of Headers makes it impossible to set headers when deserializing a message. Probably, Headers should be moved to return position of serialize:

def serialize(topic: String, a: A): F[(Array[Byte], Headers)]

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
filosgangacommented, Apr 3, 2021

I don’t believe the java serialiser allows to set headers. Does it?

0reactions
bplommercommented, Jul 17, 2021

If the problem is just that the output of Headers#toJava is immutable, I think the following should work - it converts the headers to the Java class using a constructor that makes a (shallow) defensive copy.

Does this look like it will solve the issue? If so I’m happy to incorporate it into the library, but could you first try it out and let me know how it goes?

import scala.jdk.CollectionConverters._

def fromJava[F[_], A](serializer: KafkaSerializer[A])(
  implicit F: Sync[F]
): Serializer[F, A] =
  Serializer.instance[F, A] { (topic, headers, a) =>
    F.pure(
      serializer.serialize(
        topic,
        new RecordHeaders((headers.toChain: Chain[KafkaHeader]).toIterable.asJava),
        a
      )
    )
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding encode header for REST framework - Stack Overflow
Django REST Framework Response() you can pass headers as argument class SmartTagViewSet(viewsets.
Read more >
class based views, response headers and CORS
Ideally I would need to set the headers to something like ["Access-Control-Allow-Origin"] = "*" but am unsure how to do this using these...
Read more >
Serializers - Django REST framework - Tom Christie
Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered...
Read more >
Content negotiation and serialization | Ktor
For this, it uses the Accept and Content-Type headers. ... need to add the Kotlin serialization plugin as described in the Setup section....
Read more >
Reply - Fastify
.removeHeader(key) - Remove the value of a previously set header. ... default JSON serializer or using the custom serializer (if one is set)...
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