本文整理匯總了Java中io.swagger.util.Json.mapper方法的典型用法代碼示例。如果您正苦於以下問題:Java Json.mapper方法的具體用法?Java Json.mapper怎麽用?Java Json.mapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.swagger.util.Json
的用法示例。
在下文中一共展示了Json.mapper方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testReadPath
import io.swagger.util.Json; //導入方法依賴的package包/類
public static void testReadPath() throws JsonProcessingException, IOException {
String data = "{"
+ "\"post\": { \"tags\": [\"pet\"], \"summary\": \"add a new pet to the store\", \"description\": \"\", \"operationid\": \"addpet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"405\": { \"description\": \"invalid input\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] },"
+ "\"put\": { \"tags\": [\"pet\"], \"summary\": \"update an existing pet\", \"description\": \"\", \"operationid\": \"updatepet\", \"consumes\": [\"application/json\", \"application/xml\"], \"produces\": [\"application/xml\", \"application/json\"], \"parameters\": [{ \"in\": \"body\", \"name\": \"body\", \"description\": \"pet object that needs to be added to the store\", \"required\": true, \"schema\": { \"$ref\": \"#/definitions/pet\" } }], \"responses\": { \"400\": { \"description\": \"invalid id supplied\" }, \"404\": { \"description\": \"pet not found\" }, \"405\": { \"description\": \"validation exception\" } }, \"security\": [{ \"petstore_auth\": [\"write:pets\", \"read:pets\"] }] }"
+ "}";
ObjectMapper mapper = Json.mapper();
JsonNode pathNode = mapper.readTree(data);
Path path = mapper.convertValue(pathNode, Path.class);
Json.prettyPrint(path);
}
示例2: convertToSwagger
import io.swagger.util.Json; //導入方法依賴的package包/類
private static Swagger convertToSwagger(String data) throws IOException {
ObjectMapper mapper;
if(data.trim().startsWith("{")){
mapper = Json.mapper();
}
else {
mapper = Yaml.mapper();
}
JsonNode rootNode = mapper.readTree(data);
// must have swagger node set
JsonNode swaggerNode = rootNode.get("swagger");
if(swaggerNode == null){
throw new IllegalArgumentException("Swagger String has an invalid format.");
}else{
return mapper.convertValue(rootNode, Swagger.class);
}
}
示例3: ModelResolverExt
import io.swagger.util.Json; //導入方法依賴的package包/類
public ModelResolverExt() {
super(Json.mapper());
addPropertyCreator(new BytePropertyCreator());
addPropertyCreator(new ShortPropertyCreator());
addPropertyCreator(new ByteArrayPropertyCreator());
addPropertyCreator(new InputStreamPropertyCreator());
addPropertyCreator(new PartPropertyCreator());
loadPropertyCreators();
}
示例4: ResultsParser
import io.swagger.util.Json; //導入方法依賴的package包/類
public ResultsParser(String location) throws Exception {
String data;
location = location.replaceAll("\\\\", "/");
if (location.toLowerCase().startsWith("http")) {
data = RemoteUrl.urlToString(location, null);
} else {
final String fileScheme = "file://";
Path path;
if (location.toLowerCase().startsWith(fileScheme)) {
path = Paths.get(URI.create(location));
} else {
path = Paths.get(location);
}
if (Files.exists(path)) {
data = FileUtils.readFileToString(path.toFile(), "UTF-8");
} else {
data = ClasspathHelper.loadFileFromClasspath(location);
}
}
if (data.trim().startsWith("{")) {
ObjectMapper mapper = Json.mapper();
root = mapper.readTree(data);
}
// else {
// root = DeserializationUtils.readYamlTree(data);
// }
}
示例5: getResourceSwaggerJson
import io.swagger.util.Json; //導入方法依賴的package包/類
public String getResourceSwaggerJson(){
SwaggerSerializers.setPrettyPrint(true);
ReaderConfig readerConfig = new PlayReaderConfig();
Swagger swagger = new Swagger();
PlaySwaggerConfig config = PlayConfigFactory.getConfig();
swagger.setHost(config.getHost());
swagger.setBasePath(config.getBasePath());
Info info = new Info();
info.setVersion(config.getVersion());
info.setTitle(config.getTitle());
info.setContact(new Contact().name(config.getContact()));
info.setLicense(new License().name(config.getLicense()).url(config.getLicenseUrl()));
info.setDescription(config.getDescription());
info.setTermsOfService(config.getTermsOfServiceUrl());
swagger.setInfo(info);
PlayReader reader = new PlayReader(swagger, readerConfig);
swagger = reader.read(controllerClasses);
ObjectMapper commonMapper = Json.mapper();
try {
return commonMapper.writeValueAsString(swagger);
} catch (JsonProcessingException e) {
Logger.error(e.getMessage());
return "";
}
}
示例6: getMapper
import io.swagger.util.Json; //導入方法依賴的package包/類
protected ObjectMapper getMapper(Format format) {
return format == Format.yaml ? Yaml.mapper() : Json.mapper();
}
示例7: JsonApiModelResolver
import io.swagger.util.Json; //導入方法依賴的package包/類
public JsonApiModelResolver(EntityDictionary dictionary) {
super(Json.mapper());
this.dictionary = dictionary;
}
示例8: loadModelModifier
import io.swagger.util.Json; //導入方法依賴的package包/類
public void loadModelModifier() throws GenerateException, IOException {
ObjectMapper objectMapper = Json.mapper();
if (apiSource.isUseJAXBAnnotationProcessor()) {
JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule();
if (apiSource.isUseJAXBAnnotationProcessorAsPrimary()) {
jaxbAnnotationModule.setPriority(Priority.PRIMARY);
} else {
jaxbAnnotationModule.setPriority(Priority.SECONDARY);
}
objectMapper.registerModule(jaxbAnnotationModule);
// to support @ApiModel on class level.
// must be registered only if we use JaxbAnnotationModule before. Why?
objectMapper.registerModule(new EnhancedSwaggerModule());
}
ModelModifier modelModifier = new ModelModifier(objectMapper);
List<String> apiModelPropertyAccessExclusions = apiSource.getApiModelPropertyAccessExclusions();
if (apiModelPropertyAccessExclusions != null && !apiModelPropertyAccessExclusions.isEmpty()) {
modelModifier.setApiModelPropertyAccessExclusions(apiModelPropertyAccessExclusions);
}
if (modelSubstitute != null) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(this.modelSubstitute)));
String line = reader.readLine();
while (line != null) {
String[] classes = line.split(":");
if (classes.length != 2) {
throw new GenerateException("Bad format of override model file, it should be ${actualClassName}:${expectClassName}");
}
modelModifier.addModelSubstitute(classes[0].trim(), classes[1].trim());
line = reader.readLine();
}
} catch (IOException e) {
throw new GenerateException(e);
} finally {
if (reader != null) {
reader.close();
}
}
}
ModelConverters.getInstance().addConverter(modelModifier);
}