cescoffier / vertx-microservices-workshop

Vert.x Microservices Hand's on lab
http://escoffier.me/vertx-hol/
Apache License 2.0
330 stars 196 forks source link

Failed to encode as JSON: Null key for a Map not allowed in JSON #3

Closed cmoulliard closed 8 years ago

cmoulliard commented 8 years ago

Hi,

I think that there is an error with the lab content as when we launch the docker container ("docker run -p 8081:8080 --rm --name quote-generator vertx-microservice-workshop/quote-generator"), then the next error appears when we access the following address : http://dockerhost:8081

io.vertx.core.json.EncodeException: Failed to encode as JSON: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?)
        at io.vertx.core.json.Json.encodePrettily(Json.java:73)
        at io.vertx.workshop.quote.RestQuoteAPIVerticle.lambda$start$1(RestQuoteAPIVerticle.java:49)
        at io.vertx.core.http.impl.ServerConnection.handleRequest(ServerConnection.java:286)
        at io.vertx.core.http.impl.ServerConnection.processMessage(ServerConnection.java:412)
        at io.vertx.core.http.impl.ServerConnection.handleMessage(ServerConnection.java:139)
        at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.lambda$createConnAndHandle$1(HttpServerImpl.java:709)
        at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:357)
        at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:234)

screenshot 2016-05-27 18 32 37

However, the config.json file is well packaged and available within the docker contener

docker exec -it c6649fa1f319 /bin/bash
root@c6649fa1f319:/opt# ls -la 
total 42736
drwxrwxrwx  3 root root     4096 May 27 16:26 .
drwxr-xr-x 56 root root     4096 May 27 16:26 ..
drwxr-xr-x  3 root root     4096 May 27 16:26 .vertx
-rwxrwxrwx  1 root root      410 May 27 06:56 config.json
-rwxrwxrwx  1 root root 43742687 May 27 16:25 quote-generator-1.0-SNAPSHOT-fat.jar
cmoulliard commented 8 years ago

Resolved after replacing ("string") key with ("name") here

 vertx.eventBus().<JsonObject>consumer(GeneratorConfigVerticle.ADDRESS, message -> {
        JsonObject quote = message.body();
        quotes.put(quote.getString("name"), quote);
    });
cescoffier commented 8 years ago

@cmoulliard The underlying APIs have changed a bit since I wrote this workshop, so you may find some small issue. Let me know !

Everything is going to be stabilized soon (with vert.x 3.3.0 release on its way).

BTW, we plan to remove Docker from the lab to focus on vert.x only.