views:

80

answers:

0

How can I easily convert between manually written classes and WSDL-generated equivalents?

I have a Java SE 6 thick client that calls a web service to get and store data. The client has a DAO that works with my entity classes, calls <Entity>.toDto() to convert them to DTOs, and sends/receives that data with the web service. My issue stems from the fact that the entity classes live on both sides of the service interface: client and server. Each entity has a constructor from the DTO and a toDto function:

public class EntityClass {
    public EntityClass(EntityClassDto dto);
    public EntityClassDto toDto();
    ...
}

This means I have a handwritten DTO class that the client and server both use. However, the service interface expects the WSDL-generated classes. I have tried writing conversion code between the hand-written DTO and the WSDL-generated DTO and it is tedious and error-prone.

What is a reasonable alternative to this?

Some back-story: The thick client should be able to have a configurable backend: either direct to the DB or through this web service. The aforementioned DAO is the web service based implementation and another imlpementation that is JPA-based exists.