Hi all,
I am trying to store a hashmap consisting of a byte value and a list to consul.
I am partially successful but I am getting the following error:
“Any does no take any parameters”
Here is my code:
--------- to form a byte array-------------------
import java.io.ByteArrayOutputStream
import java.io.ObjectOutputStream
val bos = new ByteArrayOutputStream
val out = new ObjectOutputStream(bos)
out.writeObject(list)
val yourBytes = bos.toByteArray
------------ to form a list-------------
val list = new util.ArrayListString
list.add(“a”)
list.add(“aa”)
----------- to create a map ----------------
var map = new util.HashMapString,Any
map.put(“query”, yourBytes)
map.put(“abc”,list)
------------ to create a json and put the json object in consul--------------
implicit def PersonEncodeJson: EncodeJson[util.HashMap[String,Any]] =
EncodeJson((p: util.HashMap[String,Any]) => (“query” := p.get(“query”)(AnyRef)) ->: (“dimension” := p.get(“abc”)(AnyRef)) ->: jEmptyObject)
AnyRef is giving me the above error.
If I don’t write it, it gives me "No implicits found for parameter EncodeJson[Any] "
----- remaining code-------
val json: Json =map.asJson(PersonEncodeJson: EncodeJson[util.HashMap[String,Any]])
val prettyprinted: String =json.spaces2
println(prettyprinted)
private val client = new ConsulClient(“localhost”)
client.setKVValue(“STIP_1.0”, prettyprinted)