![]() Then, we create a CsvMapper with our CsvSchema, and finally, we write the jsonTree to our CSV file: CsvMapper csvMapper = new CsvMapper() JsonNode firstObject = jsonTree.elements().next() įirstObject.fieldNames().forEachRemaining(fieldName -> ) ĬsvSchema csvSchema = csvSchemaBuilder.build().withHeader() To do this, we create a CsvSchema Builder and set the column headers to match the JSON field names: Builder csvSchemaBuilder = CsvSchema.builder() This determines the column headers, types, and sequence of columns in the CSV file. ![]() First, we use Jackson's ObjectMapper to read our example JSON document into a tree of JsonNode objects: JsonNode jsonTree = new ObjectMapper().readTree(new File("src/main/resources/orderLines.json"))
0 Comments
Leave a Reply. |