Unmarshall from an InputStream
<p>I have written simple object to Marshall. I am marshalling it to a <code>StringWriter</code> rather than a file. It works fine but I am unsure how would I unmarshall it. </p>

<p>This is the code I've written so far. </p>

<pre><code>public static void main(String[] args) throws JAXBException, FileNotFoundException {
    JAXBContext context = JAXBContext.newInstance(Employee.class);
    Marshaller marshaller = context.createMarshaller();

    Employee employee = new Employee();
    employee.setId(1002);
    employee.setOccupation("Software Developer");
    employee.setSalary("56000");

    StringWriter writer = new StringWriter();

    marshaller.marshal(employee, writer);
    System.out.println("Object Marshalled Successfully");

    Conversion.unMarshallingObject();
}

public static void unMarshallingObject() throws JAXBException {
    StringWriter writer = new StringWriter();
    InputStream stream = new ByteArrayInputStream(writer.toString().getBytes());

    JAXBContext context = JAXBContext.newInstance(Employee.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();

    Employee employee = (Employee) unmarshaller.unmarshal(stream);

    System.out.println("Object unmarshalled successfully");
    System.out.println("**********************************");
    System.out.println(employee.getId() + " " + employee.getOccupation() + " " + employee.getSalary());

} 
</code></pre>

<p>There are plenty of examples but all pass a file. I don't want any file. Is it possible to do it this way?</p>

<p>Thanks</p>