public static void main(String[] args) throws Exception {

        JAXBContext jc = JAXBContext.newInstance(AstronomicalObject2.class);

        XMLInputFactory xif = XMLInputFactory.newFactory();
        StreamSource xml = new StreamSource(JAXBparser.class.getClassLoader().getResourceAsStream("JAXBinput.xml"));

        XMLStreamReader xsr = xif.createXMLStreamReader(xml);

        List<AstronomicalObject2> astronomicalObjects = new ArrayList<AstronomicalObject2>();
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        while (xsr.getEventType() != XMLStreamReader.END_DOCUMENT) {
            if (xsr.isStartElement() && "AstronomicalObject".equals(xsr.getLocalName())) {
                AstronomicalObject2 object = (AstronomicalObject2) unmarshaller.unmarshal(xsr);
                astronomicalObjects.add(object);
            }
            xsr.next();
        }

        for (AstronomicalObject2 astronomicalObject : astronomicalObjects) {
            System.out.println(astronomicalObject);
        }
    }