This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-15
Channels
- # announcements (1)
- # asami (29)
- # babashka (31)
- # beginners (48)
- # calva (39)
- # cljsrn (4)
- # clojure (56)
- # clojure-dev (51)
- # clojure-doc (3)
- # clojure-europe (40)
- # clojure-gamedev (13)
- # clojure-italy (22)
- # clojure-nl (3)
- # clojure-uk (5)
- # cursive (9)
- # datomic (184)
- # events (7)
- # fulcro (8)
- # graalvm (2)
- # jobs (1)
- # malli (6)
- # meander (1)
- # nrepl (5)
- # off-topic (10)
- # pathom (9)
- # polylith (33)
- # portal (2)
- # re-frame (7)
- # reagent (12)
- # releases (3)
- # remote-jobs (3)
- # reveal (27)
- # shadow-cljs (34)
- # sql (1)
- # vim (7)
- # xtdb (62)
Hi,
I am trying to save a map of values as string. I'm able to convert and save but i could reverse the same while. read-string
throws exception when it reads date values. Is there a better way to transform only vectors, sets and maps and leave string values as such. I would like this
{"name" "john doe",
"age" "28",
"hobbies" "#{\"reading\" \"gaming\"}",
"dob" "2021-01-06 10:58",
"fav" "[\"foo\" \"bar\" \"baz\"]"}
to be transformed back to
{:name "john doe", :age 28, :hobbies #{"reading" "gaming"}, :dob "2021-01-06 10:58", :fav ["foo" "bar" "baz"]}
Thanks in advanceuser=> (pr-str {:name "john doe", :age 28, :hobbies #{"reading" "gaming"}, :dob "2021-01-06 10:58", :fav ["foo" "bar" "baz"]})
"{:name \"john doe\", :age 28, :hobbies #{\"reading\" \"gaming\"}, :dob \"2021-01-06 10:58\", :fav [\"foo\" \"bar\" \"baz\"]}"
user=> (read-string (pr-str {:name "john doe", :age 28, :hobbies #{"reading" "gaming"}, :dob "2021-01-06 10:58", :fav ["foo" "bar" "baz"]}))
{:name "john doe", :age 28, :hobbies #{"reading" "gaming"}, :dob "2021-01-06 10:58", :fav ["foo" "bar" "baz"]}
user=>
I think they’re trying to serialize only the values
which, you could still use pr-str
for that.
pr-str
actually doesnt work for me. i need the values to be saved as string to do searches on it. pr-str wraps the string in another string causing searches to fail
like, you are doing some kind of custom serialization, and expecting to be able to call read-string and have it work
im trying to use this to save in redis. when i save with pr-str
the value gets saved as "\"john doe\""
instead of "john doe"
. This is a problem. Im trying to find a way around it
generally, I dunno with redis, but like with say lucene, you would save extracted text and serialized datastrucutres separately
that was my last resort. i was hoping if there would be simpler library or way to achieve this.
generic search stuff, in order to work is going to want an undifferentiad slug of flat text
but a format like edn in clojure or json requires markers in the text to correctly deserialize
how do I import a java project using deps.edn
? is :deps only for clojars artifacts? First time trying java interop with a non-mainline library. There’s an artifact in Maven.
:deps {the.java/project {:mvn/version "1.2.3"}}
will work for a project on Maven (substitute the real coordinates of the library).
@tws are you getting an error?
the verb "import" is usually used to describe making java types available via their short name (without the package part), that is what it is called in java (the import statement) and clojure has an import macro and an :import clause for ns forms that does the same
which is a distinct thing from adding a dependency to your project (which you would do via deps.edn or project.clj, or pom.xml, or whatever)
I’m trying to pull in https://repo1.maven.org/maven2/dnsjava/dnsjava/3.4.2/
with dnsjava/dnsjava {:mvn/version "3.4.2"}
and i see the jar
in ~/.m2/repository/dnsjava/dnsjava/3.4.2
but I don’t seem able to use it correctly. Yes, @seancorfield the error says “PEBKAC”? 😆
i’ll keep at it, i’m on the right track, thanks. i am super biased against java interop syntax, and it’s holding me back
either because you are trying to use the short name without importing it, or the class you are trying to use doesn't exist
the class won't exist either because the dependency isn't correctly added, or because you are looking at examples/docs that don't correspond with the version you are using
I don't use cider so I don't know what tools it has, but if that just browses clojure namespaces, then java stuff would not be in it
depending on how it defines all namespaces, clojure stuff might not be in it either if it hasn't been loaded
ok, think I got it working. this is what happens when I flail without understanding anything.
(! 505)-> clj -Sdeps '{:deps {dnsjava/dnsjava {:mvn/version "3.4.2"}}}'
Downloading: dnsjava/dnsjava/3.4.2/dnsjava-3.4.2.pom from central
Downloading: dnsjava/dnsjava/3.4.2/dnsjava-3.4.2.jar from central
Clojure 1.10.3
user=> (import org.xbill.DNS.SimpleResolver)
org.xbill.DNS.SimpleResolver
user=> (.getAddress (SimpleResolver. ""))
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
#object[java.net.InetSocketAddress 0x659a2455 ""]
user=>
@tws Does that help ☝️:skin-tone-2: ?the java standard library is perfectly capable of resolving names to addresses without an additional dependency if that is what you want
API docs for that library are here, if that helps: https://javadoc.io/doc/dnsjava/dnsjava/latest/index.html
there are some provisos there, if I recall by default the jvm's built in resolving caches for a long time
https://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html#getByName(java.lang.String)
thanks @hiredman but I’m doing a lot of dig stuff. Yep @seancorfield that’s where I found it. I was just being a dummy on syntax.
there are a couple ancient clojure wrappers for dnsjava, but they’re all about 8+ yrs old and don’t support much of the API.
you can always do it live https://gist.github.com/hiredman/bc3ee9132e1bf52cd4f31b893bbb8d86#file-scratch-clj-L225