code_junkie

Lightweight Java persistence

Nov 13th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. static final long serialVersionUID = 1L;
  2.  
  3. JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
  4.  
  5. // unmarshal from foo.xml
  6. Unmarshaller u = jc.createUnmarshaller();
  7. FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) );
  8.  
  9. // marshal to System.out
  10. Marshaller m = jc.createMarshaller();
  11. m.marshal( fooObj, System.out );
  12.  
  13. Serializer serializer = new Persister();
  14. MyObject object = serializer.read(MyObject.class, new File("file.xml));
  15.  
  16. serializer.write(myInstance, new File("file.xml"));
Add Comment
Please, Sign In to add comment