code: static ImmutableMap<String, TypeDescriptor> verifyAndSort(Map<String, TypeDescriptor> typesByAlias) {
          List<String> sorted = new ArrayList<>();
          for (Map.Entry<String, TypeDescriptor> entry : typesByAlias.entrySet()) {
              String alias = entry.getKey();
              TypeDescriptor type = entry.getValue();
              int i = sorted.size()-1;
              for (; i >= 0; i--) {
                  TypeDescriptor other = typesByAlias.get(sorted.get(i));
                  if (other.isSuperTypeOf(type.getRawType())) {
                      break;
                  }
              }
              sorted.add(i+1, alias);
          }
  
          ImmutableMap.Builder<String, TypeDescriptor> result = ImmutableMap.builder();
          for (String alias : sorted) {
              result.put(alias, typesByAlias.get(alias));
          }
          return result.build();
      }
docs: Sorts TypeDescriptors in topological order so that super class always precedes it's sub classes.