-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom ReadHandler for tag "map" #18
Comments
Check out how transit-clj handles this: https://github.com/cognitect/transit-clj/blob/master/src/cognitect/transit.clj#L264-L291. It has it's own |
Hi @dchelimsky, I am not sure I understood the Clojure code. First of all, I don't see The problem is that the signature for the I could solve this limitation if I was able to override the "map" tag with my own ReadHandler as shown in my initial comment, but these lines in transit-java prevent me from doing that. Why does |
Ah, you're right. Sorry. I only glanced quickly and had assumed that transit-clj was providing some overrides of ground types. You're correct that you can't override them through the reader API. You'd have to dig deeper down to override the map handler and I'm not sure what the right approach would be. I'll follow up if I think of something but I'll try to get other eyes on this as well. FYI - all of the transit implementations prevent overriding ground type readers, but the intent there is to prevent library authors, writing libs in the same language as the transit impl, from pulling the rug out from under users of their libraries. Different problem than the one you're trying to solve, but at least now you know why that's there. |
Hi again @chris-zen. Expanding on my prev comment, the issue at the heart of this is composability, and it applies to maps and lists in java in the same way that it applies to the scalar ground types. If transit-java allowed lib authors to change the ground types, consumers of those libs would not be able to count on the types they're expecting. While the intent of the What's really needed here is a transit-scala lib that deals directly in scala-specific types. I believe that you could get there by forking transit-java and making just a few changes. The That help? |
Hi @dchelimsky, I really appreciate your help with this, but unfortunately working on transit-scala is out of scope for my project, that summed to the fact that binary data is represented as Base64 strings (see here) made us decide to use MessagePack instead, which has very good libraries for Clojure, Scala, Python and JavaScript, and fully covers our data needs. |
Understood, and glad you found a solution that works for you. |
I am creating custom Write and Read handlers for Scala on top of
transit-java
.I was able to implement a WriteHandler for an Scala Map structure that serializes into a "map" tag by wrapping the Scala Map into a Java Map as:
I wrote a ReadHandler too, but when I try to instantiate a new reader using my custom handler:
I get the following error:
What is the right way to write and read a Map that doesn't necessarily uses a java.util.Map structure then ? I need it to interoperate with other languages so I actually need to use the "map" tag but using an Scala Map to read, not the java.util.Map.
Thanks,
Christian
The text was updated successfully, but these errors were encountered: