diff --git a/examples/pets-cli/pom.xml b/examples/pets-cli/pom.xml index ae249bd..0d05cf9 100644 --- a/examples/pets-cli/pom.xml +++ b/examples/pets-cli/pom.xml @@ -13,7 +13,7 @@ 4.7.6 2.18.2 5.14.1 - 1.1.0 + 1.2.0 3.6.0 diff --git a/examples/pets-cli/src/main/java/rickwporter/prettytable/example/pets/PetsCli.java b/examples/pets-cli/src/main/java/rickwporter/prettytable/example/pets/PetsCli.java index 7358566..ae18e91 100644 --- a/examples/pets-cli/src/main/java/rickwporter/prettytable/example/pets/PetsCli.java +++ b/examples/pets-cli/src/main/java/rickwporter/prettytable/example/pets/PetsCli.java @@ -12,11 +12,6 @@ import java.util.Set; import java.util.concurrent.Callable; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.util.DefaultIndenter; -import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; -import com.fasterxml.jackson.databind.ObjectMapper; - import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Model.CommandSpec; @@ -25,9 +20,8 @@ import picocli.CommandLine.ParentCommand; import picocli.CommandLine.ScopeType; import picocli.CommandLine.Spec; -import rickwporter.prettytable.PrettyTable; +import rickwporter.prettytable.PrettyObject; import rickwporter.prettytable.OutputFormat; -import rickwporter.prettytable.TableBuilder; @Command( name = "pets", @@ -142,34 +136,9 @@ protected int usage(String message) { return CommandLine.ExitCode.USAGE; } - public String renderJson(Object body) { - DefaultIndenter indent = new DefaultIndenter(" ", "\n"); - DefaultPrettyPrinter printer = new DefaultPrettyPrinter() - .withArrayIndenter(indent) - .withObjectIndenter(indent); - try { - return new ObjectMapper().writer(printer).writeValueAsString(body); - } catch (JsonProcessingException ex) { - throw new IllegalStateException("Could not render JSON", ex); - } - } - private String render(Object body) { - if (body == null) { - return ""; - } - if (body instanceof String || body instanceof Number || body instanceof Boolean) { - return String.valueOf(body); - } - if (this.parent.format == OutputFormat.JSON) { - return this.renderJson(body); - } - - PrettyTable table = new TableBuilder().build(this.parent.format, body); - if (table == null) { - return ""; - } - return table.toString(); + PrettyObject pretty = new PrettyObject(); + return pretty.render(this.parent.format, body); } protected int show(Object body) {