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.

Why is there no ByteString => T deserializer?

See original GitHub issue

I can do redis.set("key", MyCustomType(42)) as long as I have a valid RedisValueConverter in implicit scope for my custom type.

But when I do redis.get("key") all I get is a raw Option[ByteString] and I have to convert it back to my custom type myself.

Why is there not a get[T: RedisValueDeserializer](key: String): Future[Option[T]] with some basic support for common types (Strings, Ints, Longs, Booleans, Lists, Sets, Maps, etc.)? Then I can have my own RedisValueDeserializer in scope to deserialize my custom types.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
agemooijcommented, Aug 25, 2013

The problem is in this call:

redis.getT(k)

This call does not specify the desired outcome type T so the compiler will look for an unambigious implementation of the type class and finds two instead of one. The solution is to call the method like this:

redis.getT[String](k)

If you plan to only provide the two default implementations you have now, then there would be a variation of the same trick that would help make it possible to call get without a type parameter, namely:

@implicitNotFound(msg = "Cannot find ByteStringDeserializer type class for ${T}")
trait ByteStringDeserializer[T] {
  def deserialize(bs: ByteString): T
}

object ByteStringDeserializer extends LowPriorityDefaultByteStringDeserializerImplicits

trait LowPriorityDefaultByteStringDeserializerImplicits extends LowerPriorityDefaultByteStringDeserializerImplicits {
  implicit object stringDeserializer extends ByteStringDeserializer[String] {
    def deserialize(bs: ByteString): String = bs.utf8String
  }
}

trait LowerPriorityDefaultByteStringDeserializerImplicits {
  implicit object byteStringDeserializer extends ByteStringDeserializer[ByteString] {
    def deserialize(bs: ByteString): ByteString = bs
  }
}

Also don’t forget to add the @implicitNotFound annotation because it will help end users to find out what they are doing wrong (i.e. the forgot to create a deserializer for their custom type).

0reactions
darshokacommented, Apr 3, 2018

why empty list " List() " is returning while using redis.get(“myKey”) ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No ByteString deserializer found for type models.MpMember ...
I found the solution. I convert the Scala object to Json and save to Redis as a string. object Member { implicit val...
Read more >
Serialization Formats - ksqlDB Documentation
ksqlDb deserializes a string as BYTES if it corresponds to a BYTES typed field in the stream. Field Name Case Sensitivity¶. The format...
Read more >
Message serializers - Lagom - Microservices Framework
Strict message serializers serialize and deserialize to and from ByteString , that is, they work strictly in memory, while streamed message serializers work ......
Read more >
Any - Google Developers
Protobuf library provides support to pack/unpack Any values in the form of utility functions or additional generated methods of the Any type.
Read more >
Deserializer in serde_json - Rust - Docs.rs
Reader-based deserializers do not support deserializing borrowed types like &str , since the std::io::Read trait has no non-copying methods – everything it does ......
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