On your transfer object, define the domain object which it maps to:

@DomainClass(domainClass = SomeDomainClass.class)

Alternatively, you define the class as text, thus preventing a (module) dependency on the domain class.


Conversion between the transfer object and domain class can now be done using:

JTransfo jTransfo = new JTransfoImpl();
SomeDomainClass domainObject = (SomeDomainClass) jTransfo.convert(transferObject);


JTransfo jTransfo = new JTransfoImpl();
SomeDomainClass domainObject = new SomeDomainClass();
jTransfo.convert(transferObject, domainObject);

Conversion from the domain object to the transfer object can be done like this:

JTransfo jTransfo = new JTransfoImpl();
SomeTransferClass transferObject = jTransfo.convert(domainObject, new SomeTransferObject());

Customizing fields

jTransfo looks at the fields in the transfer object to determine what needs to be done.
You can customize the behaviour by adding annotations.

To completely ignore a field (not mapped in either direction), you can add:

private String fieldWhichIsNotMapped;

If you want a field to be visible in the transfer object but not copied back to the domain object, you can use:

@MappedBy(readOnly = true)
private String fieldWhichIsNotCopiedToTheDomainObject;

Fields are by default mapped to a field with the same name. This can be changed:

@MappedBy(field = "fieldNameInDomainObject")
private String fieldNameInTransferObject;