當前位置: 首頁>>代碼示例>>Java>>正文


Java Json.mapper方法代碼示例

本文整理匯總了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);
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:11,代碼來源:SwaggerUtils.java

示例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);
    }
}
 
開發者ID:RobWin,項目名稱:assertj-swagger,代碼行數:18,代碼來源:Swagger20Parser.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:11,代碼來源:ModelResolverExt.java

示例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);
	// }
}
 
開發者ID:lpelleau,項目名稱:SwagTester,代碼行數:28,代碼來源:ResultsParser.java

示例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 "";
	}
}
 
開發者ID:abhishekShukla,項目名稱:swagger-play,代碼行數:34,代碼來源:ApiHelpInventory.java

示例6: getMapper

import io.swagger.util.Json; //導入方法依賴的package包/類
protected ObjectMapper getMapper(Format format) {
    return format == Format.yaml ? Yaml.mapper() : Json.mapper();
}
 
開發者ID:limberest,項目名稱:limberest,代碼行數:4,代碼來源:ServiceApi.java

示例7: JsonApiModelResolver

import io.swagger.util.Json; //導入方法依賴的package包/類
public JsonApiModelResolver(EntityDictionary dictionary) {
    super(Json.mapper());
    this.dictionary = dictionary;
}
 
開發者ID:yahoo,項目名稱:elide,代碼行數:5,代碼來源:JsonApiModelResolver.java

示例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);
}
 
開發者ID:kongchen,項目名稱:swagger-maven-plugin,代碼行數:47,代碼來源:AbstractDocumentSource.java


注:本文中的io.swagger.util.Json.mapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。