public void prettyPrintJson(PrintWriter out) throws IOException { ObjectMapper mapper = new ObjectMapper(); out.write(mapper.writeValueAsString(this.toJsonObject())); }
private static void generateJson(LinkedList<String> arguments) throws ClassNotFoundException, IOException { String catName = arguments.pollFirst(); String className = arguments.pollFirst(); String storedPath = arguments.pollFirst(); File storeDir = new File(storedPath); ThriftType.StructType structType = new ThriftSchemaConverter().toStructType((Class<? extends TBase<?, ?>>) Class.forName(className)); ObjectMapper mapper = new ObjectMapper(); String fileName = catName + ".json"; mapper.writerWithDefaultPrettyPrinter().writeValue(new File(storeDir, fileName), structType); }
private static void compareJson(LinkedList<String> arguments) throws IOException { String oldJsonPath = arguments.pollFirst(); String newJsonPath = arguments.pollFirst(); File oldJsonFile = new File(oldJsonPath); checkExist(oldJsonFile); File newJsonFile = new File(newJsonPath); checkExist(newJsonFile); ObjectMapper mapper = new ObjectMapper(); ThriftType.StructType oldStruct = mapper.readValue(oldJsonFile, ThriftType.StructType.class); ThriftType.StructType newStruct = mapper.readValue(newJsonFile, ThriftType.StructType.class); CompatibilityReport report = new CompatibilityChecker().checkCompatibility(oldStruct, newStruct); if (!report.isCompatible) { System.err.println("schema not compatible"); System.err.println(report.getMessages()); System.exit(1); } System.out.println("[success] schema is compatible"); }