View Model as Parameter
As discussed on the mailing list.
Query
I must provide a REST service accepting more complex view model as input parameter.
My view model parameter would look like
@Named("OfferTemplateFilter")
@DomainObject( nature = Nature.VIEW_MODEL )
@XmlRootElement(name = "OfferTemplateFilter")
@XmlAccessorType(XmlAccessType.FIELD)
@Getter @Setter
public class OfferTemplateFilter {
public List<String> selectedDeviceManufacturer = new ArrayList<>();
public List<String> selectedDeviceSizes = new ArrayList<>();
}
My REST domain service would be something like
@Named("OfferRestService")
@DomainService
public class OfferRestService {
@Action(semantics = SemanticsOf.IDEMPOTENT)
public OfferTemplateSelectorForCustomer
offerSelectorForCustomer(
final String subscriberNumber,
final OfferTemplateFilter filter) {
return offerSelectorRepository.create(subscriberNumber, filter);
}
...
}
I’m wondering how this could be achieved without custom rest service. Ideally the service consumer would post a kind of JSON structure where my view model OfferTemplateFilter would be created?
Possible Answer…
Rather than try to "upload" the OfferTemplateFilter view model as a parameter, instead treat it as a resource.
That is:
-
have a new service to create an instance of the filter, and then
-
update this filter (adding/removing from its two collections).
-
When done, pass a reference to the filter to the original REST service, as a regular reference.
Obviously the URL passed in the last step will be rather long and messy, but that’s not a problem per-se.