Skip Headers

# Using Java

Previous

Next

To create an XML mapping with a simple type translator with Java code in your IDE, you need the following elements:

- `EISDirectMapping` or `EISCompositeDirectCollectionMapping` or `XMLDirectMapping` or `XMLCompositeDirectCollectionMapping`

- instance of `Converter`

- instance of `TypedElementField`

Example: Creating a Type Translation XML Mapping shows how to implement your own simple type translator with an `XMLDirectMapping` to override the built-in conversion for writing XML so that TopLink writes a `Byte` array (`ClassConstants.ABYTE`) as a `Base64` (`XMLConstants.BASE64_BINARY`) encoded string.

Creating a Type Translation XML Mapping

    XMLDirectMapping mapping = new XMLDirectMapping();
    mapping.setConverter(new SerializedObjectConverter());
    TypedElementField field = new TypedElementField("element");
    field.getSimpleTypeTranslator().addJavaConversion(
        ClassConstants.ABYTE,
        new QName(XMLConstants.SCHEMA_URL, XMLConstants.BASE64_BINARY)
    );
    mapping.setField(field);