Skip to content

Instantly share code, notes, and snippets.

@ahndmal
Created November 26, 2020 18:41
Show Gist options
  • Save ahndmal/4e9e5560047decf292606a14c15ff44c to your computer and use it in GitHub Desktop.
Save ahndmal/4e9e5560047decf292606a14c15ff44c to your computer and use it in GitHub Desktop.
public class JacksonExe {
private final static String path = "D:\\Programming\\java\\projects\\documents-parsing\\src\\resources\\json\\cats.json";
private final static String jsonUrl = "https://api.privatbank.ua/p24api/exchange_rates?json&date=01.04.2020";
public static void main(String[] args) {
ObjectMapper objectMapper = new ObjectMapper();
Cat[] cats = null;
try {
cats = objectMapper.readValue(new File(path), Cat[].class);
for (Cat cat : cats ) {
System.out.println(cat.getName());
System.out.println(cat.getAge());
}
Currency currency = objectMapper.readValue(new URL(jsonUrl), Currency.class);
String currencyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(currency);
System.out.println(currencyJson);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment