Package com.skaringa.javaxml

Main interface, factory and exceptions.

See:
          Description

Interface Summary
ObjectTransformer Interface that describes the Skaringa transformer.
 

Class Summary
ObjectTransformerFactory Factory that produces concrete implementations of ObjectTransformer.
PropertyKeys This class provides string constants that can be used to set properties for ObjectTransformer.
 

Exception Summary
DeserializerException Exception that is thrown in case of errors during deserialization.
NoImplementationException Exception that is thrown if the ObjectTransformerFactory isn't able to find an implementation.
SerializerException Exception that is thrown in case of errors during serialization.
 

Package com.skaringa.javaxml Description

Main interface, factory and exceptions.

Typical usage

Serialize a Java object into a XML file

  Person fred = new Person();

  ObjectTransformer trans =
    ObjectTransformerFactory.getInstance().getImplementation();
                
  FileOutputStream out = new FileOutputStream("fred.xml");
  trans.serialize(fred, new StreamResult(out));
  out.close();

Deserialize a XML file into a Java object

  FileInputStream in = new FileInputStream("fred.xml");
  Person freddy =
    (Person) trans.deserialize(new StreamSource(in));
  in.close();

Write the XML schema definition of a Java class into a file

  out = new FileOutputStream("Person.xsd");
  trans.writeXMLSchema(Person.class, new StreamResult(out));
  out.close();

Transform a Java object into another object of different type using XSLT

  trans.setPostprocessorInstruction(new StreamSource(
    ClassLoader.getSystemResourceAsStream("Person2OrgMember.xsl")));

  OrgMember fredTheMember =
    (OrgMember) trans.transform(fred);

Serialize a Java object into a JSON file

  Person fred = new Person();

  ObjectTransformer trans =
    ObjectTransformerFactory.getInstance().getImplementation();
      
  OutputStream out = new FileOutputStream("fred.js");
  trans.serializeToJson(fred, out);
  out.close();

Deserialize from a JSON stream into a Java object

  FileInputStream in = new FileInputStream("fred.js");
  Person freddy =
    (Person) trans.deserializeFromJson(in, Person.class);
  in.close();