static <T> T fromJSON(String json, Class<T> clzz) { try { return om.readValue(json, clzz); } catch (IOException e) { throw new RuntimeException(e); } }
public void prettyPrintJson(PrintWriter out) throws IOException { ObjectMapper mapper = new ObjectMapper(); out.write(mapper.writeValueAsString(this.toJsonObject())); }
static String toJSON(Object o) { final StringWriter sw = new StringWriter(); try { om.writeValue(sw, o); } catch (IOException e) { throw new RuntimeException(e); } return sw.toString(); } }
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"); }
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); }
/** * * @param json the json representation * @return the parsed object */ public static ParquetMetadata fromJSON(String json) { try { return objectMapper.readValue(new StringReader(json), ParquetMetadata.class); } catch (JsonParseException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
private static String toJSON(SummaryData summaryData, ObjectMapper mapper) { StringWriter stringWriter = new StringWriter(); try { mapper.writeValue(stringWriter, summaryData); } catch (JsonGenerationException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return stringWriter.toString(); }
/** * parses JSON into the given class * * @param json * @param clazz * @return */ public static <T extends SummaryData> T fromJSON(String json, Class<T> clazz) { try { return objectMapper.readValue(new StringReader(json), clazz); } catch (JsonParseException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
private static String toJSON(ParquetMetadata parquetMetaData, ObjectMapper mapper) { StringWriter stringWriter = new StringWriter(); try { mapper.writeValue(stringWriter, parquetMetaData); } catch (JsonGenerationException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return stringWriter.toString(); }