or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-marshalling.mdindex.mdjaxb-implementation.mdmime-support.mdsupport-utilities.mdxstream-implementation.md
tile.json

tessl/maven-org-springframework--spring-oxm

Spring Object/XML Marshalling support providing generic interfaces for converting Java objects to XML and vice versa

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework/spring-oxm@6.2.x

To install, run

npx @tessl/cli install tessl/maven-org-springframework--spring-oxm@6.2.0

index.mddocs/

Spring OXM (Object/XML Mapping)

Spring OXM provides a comprehensive abstraction layer for XML marshalling and unmarshalling operations in Java applications. It offers generic Marshaller and Unmarshaller interfaces that enable developers to convert Java objects to XML and vice versa using various underlying technologies such as JAXB, XStream, and other XML binding frameworks.

Package Information

  • Package Name: org.springframework:spring-oxm
  • Package Type: Maven
  • Language: Java
  • Installation: Add to Maven dependencies:
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-oxm</artifactId>
    <version>6.2.8</version>
</dependency>

Or Gradle:

implementation 'org.springframework:spring-oxm:6.2.8'

Core Imports

import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.oxm.xstream.XStreamMarshaller;
import org.springframework.oxm.mime.MimeMarshaller;
import org.springframework.oxm.mime.MimeUnmarshaller;
import org.springframework.oxm.mime.MimeContainer;

Basic Usage

import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.StringWriter;
import java.io.StringReader;

// Configure JAXB marshaller
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(MyClass.class);
marshaller.afterPropertiesSet();

// Marshal object to XML
MyClass object = new MyClass();
StringWriter writer = new StringWriter();
marshaller.marshal(object, new StreamResult(writer));
String xml = writer.toString();

// Unmarshal XML to object
StringReader reader = new StringReader(xml);
MyClass unmarshalled = (MyClass) marshaller.unmarshal(new StreamSource(reader));

Architecture

Spring OXM follows an abstraction pattern with:

  • Core Interfaces: Generic Marshaller/Unmarshaller contracts
  • Technology Implementations: JAXB, XStream concrete implementations
  • MIME Support: Extensions for binary data handling via MTOM/XOP/SwA
  • Support Classes: Base classes and utilities for common operations
  • Configuration: Spring XML namespace support for declarative setup

Capabilities

Core Marshalling/Unmarshalling

Primary interfaces for XML marshalling and unmarshalling operations with support for type checking and generic types.

public interface Marshaller {
    boolean supports(Class<?> clazz);
    void marshal(Object graph, Result result) throws IOException, XmlMappingException;
}

public interface Unmarshaller {
    boolean supports(Class<?> clazz);
    Object unmarshal(Source source) throws IOException, XmlMappingException;
}

public interface GenericMarshaller extends Marshaller {
    boolean supports(Type genericType);
}

public interface GenericUnmarshaller extends Unmarshaller {
    boolean supports(Type genericType);
}

Core Marshalling Interfaces

JAXB Implementation

Complete JAXB 2.x implementation with full marshalling/unmarshalling capabilities, validation, schema support, and security features.

public class Jaxb2Marshaller implements GenericMarshaller, GenericUnmarshaller, 
                                       MimeMarshaller, MimeUnmarshaller, 
                                       BeanClassLoaderAware, InitializingBean {
    public void setClassesToBeBound(Class<?>... classesToBeBound);
    public void setContextPaths(String... contextPaths);
    public void setSchema(Resource schemaResource);
    public void setValidationEventHandler(ValidationEventHandler validationEventHandler);
    // Additional configuration methods...
}

JAXB Implementation

XStream Implementation

XStream-based marshaller implementation with security controls and converter configuration for alternative XML processing.

public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLoaderAware, InitializingBean {
    public void setSupportedClasses(Class<?>... supportedClasses);
    public void setTypePermissions(TypePermission... typePermissions);
    public void setConverters(ConverterMatcher... converters);
    public void setMarshallingStrategy(MarshallingStrategy marshallingStrategy);
    // Additional configuration methods...
}

XStream Implementation

MIME Attachment Support

Extensions for handling binary data through MIME attachments using MTOM, XOP, or SwA protocols.

public interface MimeMarshaller extends Marshaller {
    void marshal(Object graph, Result result, MimeContainer mimeContainer) 
        throws XmlMappingException, IOException;
}

public interface MimeUnmarshaller extends Unmarshaller {
    Object unmarshal(Source source, MimeContainer mimeContainer) 
        throws XmlMappingException, IOException;
}

public interface MimeContainer {
    boolean isXopPackage();
    boolean convertToXopPackage();
    void addAttachment(String contentId, DataHandler dataHandler);
    DataHandler getAttachment(String contentId);
}

MIME Attachment Support

Support Utilities

Base classes and utility functions for common marshalling operations and Spring integration.

public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
    // Base implementation with format-specific abstract methods
}

public class MarshallingSource extends SAXSource {
    public MarshallingSource(Marshaller marshaller, Object content);
    public Marshaller getMarshaller();
    public Object getContent();
}

public abstract class SaxResourceUtils {
    public static InputSource createInputSource(Resource resource) throws IOException;
    public static String getSystemId(Resource resource);
}

Support Utilities

Exception Hierarchy

public abstract class XmlMappingException extends NestedRuntimeException {
    public XmlMappingException(String msg);
    public XmlMappingException(String msg, Throwable cause);
}

public abstract class MarshallingException extends XmlMappingException {
    // Base for marshalling-related exceptions
    protected MarshallingException(String msg);
    protected MarshallingException(String msg, Throwable cause);
}

public class MarshallingFailureException extends MarshallingException {
    public MarshallingFailureException(String msg);
    public MarshallingFailureException(String msg, Throwable cause);
}

public class UnmarshallingFailureException extends MarshallingException {
    public UnmarshallingFailureException(String msg);
    public UnmarshallingFailureException(String msg, Throwable cause);
}

public class ValidationFailureException extends XmlMappingException {
    public ValidationFailureException(String msg);
    public ValidationFailureException(String msg, Throwable cause);
}

public class UncategorizedMappingException extends XmlMappingException {
    public UncategorizedMappingException(String msg, Throwable cause);
}