2016-12-13 1 views
0

Wie Erstellen das ID-Feld entfernen ("id": "urn: jsonschema: org: gradle: Person") von JSON Schema mit Jackson erstellt?"id" von JSON Schema entfernen, wenn es von POJO mit jackson

generierte Schema

{ 
    "type" : "object", 
    "id" : "urn:jsonschema:org:gradle:Person", 
    "properties" : { 
    "name" : { 
     "type" : "string" 
    } 
    } 
} 

Für POJO Klasse (Person.class)

import com.fasterxml.jackson.annotation.JsonProperty; 

public class Person { 

    @JsonProperty("name") 
    private String name; 

} 

mit JSON Schema Generator

import java.io.IOException; 

import com.fasterxml.jackson.databind.ObjectMapper; 
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; 
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; 


public final class GetJsonSchema { 
    public static String getJsonSchema2(Class clazz) throws IOException { 
     ObjectMapper mapper = new ObjectMapper(); 
     JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(mapper); 
     JsonSchema jsonSchema = jsonSchemaGenerator.generateSchema(clazz); 
     return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema); 
    } 
} 

Ausgeführt wie

System.out.println(JsonSchema.Create(Person.class)); 

Antwort

1

einfach eingestellt ID null. Z. B .:

jsonSchema.setId(null); 
+0

Das funktioniert gut, wenn die POJO simples ist, was passiert, wenn die POJO mit inneren Objekte komplex ist? –

Verwandte Themen