public static String getSchema(Class<?> objectClass, String mediaType) {
        try {

            if (mediaType == MediaType.APPLICATION_JSON) {

                String schemaDef = null;

                if (schemaMap == null) {
                    schemaMap = new HashMap<Class<?>, String>();
                }
                if (schemaMap.containsKey(objectClass)) {
                    schemaDef = schemaMap.get(objectClass);

                } else {

                    ObjectMapper objectMapper = new ObjectMapper();
                    SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
                    objectMapper.acceptJsonFormatVisitor(objectClass, visitor);
                    JsonSchema schema = visitor.finalSchema();
                    schemaDef = objectMapper.writeValueAsString(schema);
                    schemaMap.put(objectClass, schemaDef);
                }

                return schemaDef;

            } else if (mediaType == MediaType.APPLICATION_XML) {
                JAXBContext jc = JAXBContext.newInstance(objectClass);
                // generate the schemas
                final ArrayList<ByteArrayOutputStream> schemaStreams = new ArrayList<ByteArrayOutputStream>();
                jc.generateSchema(new SchemaOutputResolver() {
                    @Override
                    public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        schemaStreams.add(out);
                        StreamResult streamResult = new StreamResult(out);
                        streamResult.setSystemId("");
                        return streamResult;
                    }
                });

                // convert to a list of string
                List<String> schemas = new ArrayList<String>();
                for (ByteArrayOutputStream os : schemaStreams) {
                    schemas.add(os.toString());

                }

                return schemaStreams.get(0).toString();

            }

        } catch (JAXBException e) {
            log.error("Error during translation, Caused by:" + e.getMessage() + ", returning null");
            return null;
        } catch (IOException e) {
            log.error("Error during translation, Caused by:" + e.getMessage() + ", returning null");
        }
        return null;
    }
public static String getSchema ( Class < ? > objectClass , String mediaType ) { try { if ( mediaType == MediaType . APPLICATION_JSON ) { String schemaDef = null ; if ( schemaMap == null ) { schemaMap = new HashMap < Class < ? > , String > ( ) ; } if ( schemaMap . containsKey ( objectClass ) ) { schemaDef = schemaMap . get ( objectClass ) ; } else { ObjectMapper objectMapper = new ObjectMapper ( ) ; SchemaFactoryWrapper visitor = new SchemaFactoryWrapper ( ) ; objectMapper . acceptJsonFormatVisitor ( objectClass , visitor ) ; JsonSchema schema = visitor . finalSchema ( ) ; schemaDef = objectMapper . writeValueAsString ( schema ) ; schemaMap . put ( objectClass , schemaDef ) ; } return schemaDef ; } else if ( mediaType == MediaType . APPLICATION_XML ) { JAXBContext jc = JAXBContext . newInstance ( objectClass ) ; final ArrayList < ByteArrayOutputStream > schemaStreams = new ArrayList < ByteArrayOutputStream > ( ) ; jc . generateSchema ( new SchemaOutputResolver ( ) { @ Override public Result createOutput ( String namespaceUri , String suggestedFileName ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; schemaStreams . add ( out ) ; StreamResult streamResult = new StreamResult ( out ) ; streamResult . setSystemId ( "" ) ; return streamResult ; } } ) ; List < String > schemas = new ArrayList < String > ( ) ; for ( ByteArrayOutputStream os : schemaStreams ) { schemas . add ( os . toString ( ) ) ; } return schemaStreams . get ( 0 ) . toString ( ) ; } } catch ( JAXBException e ) { log . error ( "Error during translation, Caused by:" + e . getMessage ( ) + ", returning null" ) ; return null ; } catch ( IOException e ) { log . error ( "Error during translation, Caused by:" + e . getMessage ( ) + ", returning null" ) ; } return null ; }
@param objectClass
@param mediaType
@return