I have the following XML which I want to unmarshall using JAXB:
<?xml version="1.0" encoding="UTF-8"?>
<questions>
<question id="1">
<text>What is the capital of Germany?</text>
<correctAnswer>2</correctAnswer>
<answers>
<answer id="1">
<text>Munich</text>
</answer>
<answer id="2">
<text>Berlin</text>
</answer>
</answers>
</question>
<question id="2">
<text>What is the capital of France?</text>
<correctAnswer>1</correctAnswer>
<answers>
<answer id="1">
<text>Paris</text>
</answer>
<answer id="2">
<text>Marseille</text>
</answer>
</answers>
</question>
</questions>
I want to create a HashMap:
HashMap<String, Question>
from which I can get the questions by their ID.
Each question object should also have a Hashmap:
HashMap<String, Answer>
from which I can get the answers by their ID.
I started off using the code from this thread: JAXB unmarshal XML elements to HashMap
Now I have two problems / questions:
The accepted answer in that thread suggests using "@XmlPath(".")", but for that I'm supposed to import an eclipse plugin:
import org.eclipse.persistence.oxm.annotations.XmlPath;
But I'm using IntelliJ, and I don't know which alternative import to use to get this working.
Even if I get the proposed solution "@XmlPath(".")" working, I still don't know how to implement the HashMap property within the question object (containing the answers).