title: Generic API design and validations for notification system java
body: <p>I am trying to build a generic notification service for sending different notifications(Email, SMS or Mobile Push) to clients whenever some event happens. This service would be in turn calling a publisher/ subscriber event based system somewhat similar to this: <a href="https://sites.google.com/site/jeffhartkopf/notifier" rel="nofollow noreferrer">https://sites.google.com/site/jeffhartkopf/notifier</a>. Whenever some event happens, it gets published on SQS from where the subscriber reads it and sends the notification.</p>
  
  <p>API interface for publisher:</p>
  
  <ol>
  <li><p>Notification Sender class would have:</p>
  
  <p>sendNotification(Object payload, Map attributeMap)</p></li>
  </ol>
  
  <p>Here, the payload contains the parameters that are variable in text of Email/SMS/push notification template. For example: If email has "Hello $name", the payload object would have name as a field and value set as the name of the client you wish to send the notification to:</p>
  
  <pre><code>@EventType("name"= "Recommendations")
  
  class PayloadObject {
     @Getter @Setter
     String name;
  }
  </code></pre>
  
  <p>Here, Event type is custom annotation to know the type of event for which notification is to be sent, which clients are expected to use while sending their payload objects.</p>
  
  <ol start="2">
  <li>Transformers:
  Now to publish an event we need serialized JSON or XML Strings which will be published. So I thought of taking the Object payload from clients of my service and using JSON or XML transformers in my service based on the event type and templates.
  Attribute map is for extra information like email attachment files which you do not want to parse from Json or xml serialized objects. For bulk data payloads will be used.</li>
  </ol>
  
  <p>The problem I see in this approach is that Object payload is too generic that there would be no type safety at all. Like the clients of this service can send in junk objects and there would not be any checks that I can think of to validate this in my service.
  Is there a way I can validate the parameters in templates (Velocity or XSLT format) against the object that is being sent by clients. Like may be making the client write unit tests corresponding to each template and payload Object? Or can I model my API in a better way rather than taking an Object from the client to ensure type safety while calling my API.</p>