mercredi 11 août 2021

how to check if top level class

Having object of Class type how to check if it's top level class / regular object class? Context: I'm converting object metadata to json structure and currently my code looks like

JsonElement toJson(Type type) {
  if (type == String.class) {
    ...
  } else if (...) { //more primitives
    ...
  } else if (type instanceof ParametrizedType) {
    ...
  } else if (type instanceof Class) {
    Class clazz = (Class) type;
    if (clazz.isEnum()) {
    ....
    }
    // probably it's an object
  }
}




Aucun commentaire:

Enregistrer un commentaire