code: public static Object toObject(InputStream is, Class<?> objectClass, String mediaType) {
          Object output = null;
  
          try {
              output = objectClass.newInstance();
  
              if (MediaType.APPLICATION_XML.equals(mediaType)) {
  
                  output = xmlMapper.readValue(is, objectClass);
  
              } else if (MediaType.APPLICATION_JSON.equals(mediaType)) {
  
                  output = mapper.readValue(is, objectClass);
  
              }
          } catch (InstantiationException e) {
              log.warn("Error while converting String to Object using JAXB:" + e.getMessage());
              return null;
          } catch (IllegalAccessException e) {
              log.warn("Error while converting String to Object using JAXB:" + e.getMessage());
              return null;
          } catch (JsonParseException e) {
              log.error(e.getMessage());
          } catch (JsonMappingException e) {
              log.error(e.getMessage());
          } catch (IOException e) {
              log.error(e.getMessage());
          }
          return output;
      }
docs: Converts <code>InputStream</code> to Object using JAXB
  
  @param str
  @param objectClass
  @return