title: Inner class for each member of enum?
body: <p>Not sure if what I want is possible but I am trying to create an enum in which each member has its own inner class. These inner classes will all have the same name <code>Context</code> but will be implemented individually.</p>
  
  <p>Ideally I would like them to be usable as such:</p>
  
  <pre><code>private handleType (MyEnum type) {
      switch (type) {
  
          case ENUM_VAL1:
              MyEnum.ENUM_VAL1.Context context = new MyEnum.ENUM_VAL1.Context();
              handleContext1(context);
              break;
  
          case ENUM_VAL2:
              MyEnum.ENUM_VAL2.Context context = new MyEnum.ENUM_VAL1.Context();
              handleContext2(context);
              break;
  
          case ENUM_VAL3:
              MyEnum.ENUM_VAL3.Context context = new MyEnum.ENUM_VAL1.Context();
              handleContext3(context);
              break;
  
          default:
              break;
  }
  </code></pre>
  
  <p>Open to other way of implementing this. But basically I need a switchable enum where each member has a "value" (1,2,3...) and also a means of associating said enums with a unique class with constructor.</p>
  
  <p>EDIT: Some background. This is to be used between two services who communicate via JSON http requests. The requests will contain some metadata, one field of which is an integer that maps to the enum. The context is a POJO, but is different for each ENUM_VALUE. Essentially, the context will be constructed and serialized into JSON. This json will effectively be just a String field called context within the top level json request. On the receiving service, there will be a switch on ENUM_VALUE, where the context is decoded appropriately and then dispatched to its appropriate handler.</p>
  
  <p>EDIT2: This enum will be shared between the two services.</p>
  
  <p>EDIT3: Here is a more explicit explanation of what I am attempting to do.</p>
  
  <p>MyServiceRequest:</p>
  
  <pre><code>public class MyServiceRequest {
      String meta1;
      String meta2;
      int typeID;
      String context;
  }
  </code></pre>
  
  <p>generating request:</p>
  
  <pre><code>MyServiceRequest req = new MyServiceRequest();
  req.meta1 = ...
  req.meta2 = ...
  req.typeID = MyEnum.ENUM_VALUE.getCode(); // int
  
  MyEnum.ENUM_VALUE.Context context = new MyEnum.ENUM_VALUE.Context(); // factory would be fine as well
  ... // populate context
  req.context = toJSON(context);
  requestJSON = toJSON(req);
  post(requestJSON);
  </code></pre>
  
  <p>decoding request:</p>
  
  <pre><code>MyServiceRequest req = ...
  MyEnum type = new MyEnum(req.typeID);
  switch(type) {
      case ENUM_VALUE:
          MyEnum.ENUM_VALUE.Context context = fromJSON(req.context, MyEnum.ENUM_VALUE.Context.class);
          doSomething(context);
  </code></pre>