Created
November 26, 2020 18:41
-
-
Save ahndmal/4e9e5560047decf292606a14c15ff44c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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