diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-06-03 20:36:07 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-06-03 20:36:07 +0200 |
commit | 98a75846c69f53f17389401096d2a19c697045d3 (patch) | |
tree | 8b9512c9dc66abfa0accec59761f25ed487728d6 /src/eu/equalparts/cardbase/query | |
parent | c072ed0ac345a7e421cb0612048d4cd534bf6e73 (diff) |
Have a working example to parse JSON sets and get cards by number
Diffstat (limited to 'src/eu/equalparts/cardbase/query')
-rw-r--r-- | src/eu/equalparts/cardbase/query/Test.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/eu/equalparts/cardbase/query/Test.java b/src/eu/equalparts/cardbase/query/Test.java new file mode 100644 index 0000000..646139e --- /dev/null +++ b/src/eu/equalparts/cardbase/query/Test.java @@ -0,0 +1,72 @@ +package eu.equalparts.cardbase.query; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import eu.equalparts.cardbase.data.Card; +import eu.equalparts.cardbase.data.CardSet; + +public class Test { + +// public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { +// ObjectMapper mapper = new ObjectMapper(); +// mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); +// +// @SuppressWarnings("unchecked") +// List<Card> allCards = getAllCards((Map<String, CardSet>) mapper +// .readValue(new File("AllSets.json"), new TypeReference<Map<String, CardSet>>() {})); +// +// System.out.println("Number of cards: " + allCards.size()); +// } +// +// public static List<Card> getAllCards(Map<String, CardSet> sets) { +// List<Card> allCards = new ArrayList<Card>(); +// +// for (CardSet set : sets.values()) { +// for (Card card : set.getCards()) { +// card.setSetCode(set.getCode()); +// card.setSetName(set.getName()); +// // System.out.println(set.getName() + ": " + card.getName()); +// +// allCards.add(card); +// } +// } +// +// return allCards; +// } + + public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + +// @SuppressWarnings("unchecked") + CardSet set = mapper.readValue(new File("M15.json"), CardSet.class); + System.out.println(set.getCardByNumber("281").getName()); + + } + + public static List<Card> getAllCards(Map<String, CardSet> sets) { + List<Card> allCards = new ArrayList<Card>(); + + for (CardSet set : sets.values()) { + for (Card card : set.getCards()) { + card.setSetCode(set.getCode()); + card.setSetName(set.getName()); + // System.out.println(set.getName() + ": " + card.getName()); + + allCards.add(card); + } + } + + return allCards; + } +} |