@Consumes({ MediaType.WILDCARD })
@Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ERROR })
public Response addToList(@PathParam("domainType") String domainType, @PathParam("instanceId") final String instanceId, @PathParam("collectionId") final String collectionId, final InputStream body) {
init(Where.PARENTED_TABLES);
final ObjectAdapter objectAdapter = getObjectAdapterElseThrowNotFound(domainType, instanceId);
final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), objectAdapter);
final OneToManyAssociation collection = helper.getCollectionThatIsVisibleForIntent(collectionId, Intent.MUTATE, getResourceContext().getWhere());
if (!collection.getCollectionSemantics().isListOrArray()) {
throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.METHOD_NOT_ALLOWED, "Collection '%s' does not have list or array semantics", collectionId);
}
final ObjectSpecification collectionSpec = collection.getSpecification();
final String bodyAsString = DomainResourceHelper.asStringUtf8(body);
final ObjectAdapter argAdapter = helper.parseAsMapWithSingleValue(collectionSpec, bodyAsString);
final Consent consent = collection.isValidToAdd(objectAdapter, argAdapter);
if (consent.isVetoed()) {
throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.UNAUTHORIZED, consent.getReason());
}