package io.vertx.example.webclient.response.jsonpojo;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.json.JsonObject;
import io.vertx.example.util.Runner;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.codec.BodyCodec;

/*
 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
 */
public class Client extends AbstractVerticle {

  // Convenience method so you can run it in your IDE
  public static void main(String[] args) {
    Runner.runExample(Client.class);
  }

  public static class User {
    public String firstName;
    public String lastName;
    public boolean male;
  }

  @Override
  public void start() throws Exception {

    vertx.createHttpServer().requestHandler(req -> {
      req.response()
        .putHeader("Content/type", "application/json")
        .end(new JsonObject()
          .put("firstName", "Date")
          .put("lastName", "Cooper")
          .put("male", true)
          .encode()
        );

    }).listen(8080, listenResult -> {
      if (listenResult.failed()) {
        System.out.println("Could not start HTTP server");
        listenResult.cause().printStackTrace();
      } else {

        WebClient client = WebClient.create(vertx);

        client.get(8080, "localhost", "/")
          .as(BodyCodec.json(User.class))
          .send(ar -> {
            if (ar.succeeded()) {
              HttpResponse<User> response = ar.result();
              System.out.println("Got HTTP response body");
              User user = response.body();
              System.out.println("FirstName " + user.firstName);
              System.out.println("LastName " + user.lastName);
              System.out.println("Male " + user.male);
            } else {
              ar.cause().printStackTrace();
            }
          });
      }
    });
  }
}

@@ -91,46 +91,8 @@
 le;%0A
-import io.vertx.core.json.JsonObject;%0A
 impo
@@ -687,501 +687,8 @@
  %7B%0A%0A
-    vertx.createHttpServer().requestHandler(req -%3E %7B%0A      req.response()%0A        .putHeader(%22Content/type%22, %22application/json%22)%0A        .end(new JsonObject()%0A          .put(%22firstName%22, %22Date%22)%0A          .put(%22lastName%22, %22Cooper%22)%0A          .put(%22male%22, true)%0A          .encode()%0A        );%0A%0A    %7D).listen(8080, listenResult -%3E %7B%0A      if (listenResult.failed()) %7B%0A        System.out.println(%22Could not start HTTP server%22);%0A        listenResult.cause().printStackTrace();%0A      %7D else %7B%0A%0A    
     
@@ -736,20 +736,16 @@
 );%0A%0A    
-  
-  
 client.g
@@ -777,20 +777,16 @@
 )%0A      
-    
 .as(Body
@@ -815,20 +815,16 @@
 )%0A      
-   
- 
 .send(ar
@@ -829,20 +829,16 @@
 ar -%3E %7B%0A
-    
         
@@ -859,20 +859,16 @@
 ed()) %7B%0A
-    
         
@@ -914,36 +914,32 @@
 lt();%0A          
-    
 System.out.print
@@ -978,20 +978,16 @@
         
-    
 User use
@@ -1009,36 +1009,32 @@
 dy();%0A          
- 
-   
 System.out.print
@@ -1070,36 +1070,32 @@
 ame);%0A          
-    
 System.out.print
@@ -1133,28 +1133,24 @@
 ;%0A          
- 
-   
 System.out.p
@@ -1186,20 +1186,16 @@
         
-    
 %7D else %7B
@@ -1205,20 +1205,16 @@
         
-  
-  
 ar.cause
@@ -1247,36 +1247,12 @@
     
-    %7D%0A          %7D);%0A      
 %7D%0A
+  
     

Fix incorrect example