How in WSDL-first approach write DTO with some (for example: validation) method? Just not to write "anemic domain model"

StackOverflow https://stackoverflow.com/questions/14724501

  •  07-03-2022
  •  | 
  •  

Question

I am using WSDL-first. I have WSDL and generate Java code using Maven plugin 'cxf-codegen-plugin'. Using Code-first one can write DTO for example:

public class ServiceSearchCriteria {
    private String phoneNumber;
    private String businessId;

    public boolean validateSearchCriteria() {
        if ((phoneNumber != null) || (businessId != null)) {
            return true;
        }
        return false;
    }
    //... setters/getters etc.
}

So using Code-First (Java-First) it is easy to write DTO with validation method. Client can check if search criteria are good fulfilled. This class would be returned by WebService class annotiated with @WebService. And this will work.

But how to write such DTO (with some method) using WSDL-First approach?

I very like WSDL-First approach (it has many advantages but this is not place to write about them) but I would like to add method... just not to write "anemic domain model" and allowing client to check search criteria fulfilled before sending to server.

Was it helpful?

Solution

You seem to be mixing various concepts. It's cool you don't want to have an anemic domain model but that has nothing to do with your DTOs which in turn has nothing to do with how the classes from WSDL look like.

A DTO has state but no behavior. Hence, they have only getters/setters but contain no logic (e.g. validation).

The objects in the domain model have state and behavior (unless they're anemic of course).

So, if there's a need for DTOs, which depends on your architecture, you'd be converting business objects from the domain model to DTOs and vice versa. If you consider the classes generated from your WSDL DTOs which would be ok then you need to convert those to your business objects. "Converting" in this respect means transferring their state.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top