当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.getFactory方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.getFactory方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.getFactory方法的具体用法?Java ObjectMapper.getFactory怎么用?Java ObjectMapper.getFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.getFactory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toJson

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * @return A json representation of the topology. Intended for printing only.
 */
public static final String toJson(ITopology topo, boolean pretty) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    if (pretty)
        mapper.enable(SerializationFeature.INDENT_OUTPUT);

    StringWriter sw = new StringWriter();
    JsonFactory f = mapper.getFactory();

    JsonGenerator g = f.createGenerator(sw);

    g.writeStartObject();
    // use TreeSet to sort the list
    g.writeObjectField("switches", new TreeSet<String>(topo.getSwitches().keySet()));
    g.writeObjectField("links", new TreeSet<String>(topo.getLinks().keySet()));
    g.writeEndObject();
    g.close();

    return sw.toString();
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:23,代码来源:TopologyPrinter.java

示例2: multiDimTest

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void multiDimTest() throws JsonProcessingException, IOException
{
	String json = "{\"request\":{\"values\":[[1.0]]}}";

	System.out.println(json);
	ObjectMapper mapper = new ObjectMapper();
	JsonFactory factory = mapper.getFactory();
	JsonParser parser = factory.createParser(json);
	JsonNode j = mapper.readTree(parser);
	JsonNode values = j.get("request").get("values");
	
	double[][] v = mapper.readValue(values.toString(),double[][].class);
	double[] vs = Doubles.concat(v);
	int[] shape = {v.length,v[0].length };
	((ObjectNode) j.get("request")).replace("values",mapper.valueToTree(vs));
	((ObjectNode) j.get("request")).set("shape",mapper.valueToTree(shape));
	System.out.println(j.toString());
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:20,代码来源:TestJsonParse.java

示例3: of

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Creates a new {@link Exporter} instance.
 *
 * @param db         the db
 * @return the exporter instance
 */
public static Exporter of(Nitrite db) {
    Exporter exporter = new Exporter();
    exporter.db = db;

    ObjectMapper objectMapper = new JacksonMapper().getObjectMapper();
    exporter.jsonFactory = objectMapper.getFactory();
    exporter.options = new ExportOptions();
    return exporter;
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:16,代码来源:Exporter.java

示例4: of

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Creates a new {@link Importer} instance.
 *
 * @param db the db
 * @return the importer instance
 */
public static Importer of(Nitrite db) {
    Importer importer = new Importer();
    importer.db = db;
    ObjectMapper objectMapper = new JacksonMapper().getObjectMapper();
    importer.jsonFactory = objectMapper.getFactory();
    return importer;
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:14,代码来源:Importer.java

示例5: create

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static MessagePackConverterFactory create(ObjectMapper mapper)
{
    if (mapper == null) {
        throw new IllegalArgumentException("'mapper' is null");
    }

    if (!(mapper.getFactory() instanceof MessagePackFactory)) {
        throw new IllegalArgumentException("'mapper' doesn't have MessagePackFactory");
    }

    return new MessagePackConverterFactory(mapper);
}
 
开发者ID:komamitsu,项目名称:retrofit-converter-msgpack,代码行数:14,代码来源:MessagePackConverterFactory.java

示例6: testJacksonParsing

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testJacksonParsing() throws IOException {
    ObjectMapper mapper = IndexV1Updater.getObjectMapperInstance(FAKE_REPO_ID);
    // the app ignores all unknown fields when complete, do not ignore during dev to catch mistakes
    mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    JsonFactory f = mapper.getFactory();
    JsonParser parser = f.createParser(TestUtils.copyResourceToTempFile("guardianproject_index-v1.json"));

    Repo repo = null;
    App[] apps = null;
    Map<String, String[]> requests = null;
    Map<String, List<Apk>> packages = null;

    parser.nextToken(); // go into the main object block
    while (true) {
        String fieldName = parser.nextFieldName();
        if (fieldName == null) {
            break;
        }
        switch (fieldName) {
            case "repo":
                repo = parseRepo(mapper, parser);
                break;
            case "requests":
                requests = parseRequests(mapper, parser);
                break;
            case "apps":
                apps = parseApps(mapper, parser);
                break;
            case "packages":
                packages = parsePackages(mapper, parser);
                break;
        }
    }
    parser.close(); // ensure resources get cleaned up timely and properly

    RepoDetails indexV0Details = getFromFile("guardianproject_index.xml",
            Repo.PUSH_REQUEST_ACCEPT_ALWAYS);
    indexV0Details.apps.size();

    assertEquals(indexV0Details.apps.size(), apps.length);
    assertEquals(apps.length, packages.size());

    int totalApks = 0;
    for (String packageName : packages.keySet()) {
        totalApks += packages.get(packageName).size();
    }
    assertEquals(totalApks, indexV0Details.apks.size());

    assertEquals(indexV0Details.icon, repo.icon);
    assertEquals(indexV0Details.timestamp, repo.timestamp / 1000); // V1 is in millis
    assertEquals(indexV0Details.name, repo.name);
    assertArrayEquals(indexV0Details.mirrors, repo.mirrors);

    ArrayList<String> installRequests = new ArrayList<>();
    for (RepoPushRequest repoPushRequest : indexV0Details.repoPushRequestList) {
        if ("install".equals(repoPushRequest.request)) {
            installRequests.add(repoPushRequest.packageName);
        }
    }
    assertArrayEquals(installRequests.toArray(), requests.get("install"));
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:63,代码来源:IndexV1UpdaterTest.java

示例7: watchSeldonSeldonDeployments

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public int watchSeldonSeldonDeployments(int resourceVersion,int resourceVersionProcessed) throws ApiException, JsonProcessingException, IOException
{
	String rs = null;
	if (resourceVersion > 0)
		rs = ""+resourceVersion;
	logger.info("Watching with rs "+rs);
	CustomObjectsApi api = new CustomObjectsApi();
	Watch<Object> watch = Watch.createWatch(
               client,
               api.listNamespacedCustomObjectCall("machinelearning.seldon.io", "v1alpha1", "default", "seldondeployments", null, null, rs, true, null, null),
               new TypeToken<Watch.Response<Object>>(){}.getType());
	
	int maxResourceVersion = resourceVersion;
	try{
       for (Watch.Response<Object> item : watch) {
       	Gson gson = new GsonBuilder().create();
   		String jsonInString = gson.toJson(item.object);
    	logger.info(String.format("%s\n : %s%n", item.type, jsonInString));
   		ObjectMapper mapper = new ObjectMapper();
   	    JsonFactory factory = mapper.getFactory();
   	    JsonParser parser = factory.createParser(jsonInString);
   	    JsonNode actualObj = mapper.readTree(parser);
   	    if (actualObj.has("kind") && actualObj.get("kind").asText().equals("Status"))
   	    {
   	    	logger.warn("Possible old resource version found - resetting");
   	    	return 0;
   	    }
   	    else
   	    {
   	    	int resourceVersionNew = actualObj.get("metadata").get("resourceVersion").asInt();
   	    	if (resourceVersionNew <= resourceVersionProcessed)
   	    	{
   	    		logger.warn("Looking at already processed request - skipping");
   	    	}
   	    	else
   	    	{
   	    		if (resourceVersionNew > maxResourceVersion)
       	    		maxResourceVersion = resourceVersionNew;

   	    		String jsonModified = removeCreationTimestampField(jsonInString);
   	    		SeldonDeployment.Builder mlBuilder = SeldonDeployment.newBuilder();
   	    		ProtoBufUtils.updateMessageBuilderFromJson(mlBuilder, jsonModified);
   	    		
   	    		this.processWatch(mlBuilder.build(), item.type);
   	    	}
   	    }
       }
	}
	catch(RuntimeException e)
	{
		if (e.getCause() instanceof SocketTimeoutException)
			return maxResourceVersion;
		else
			throw e;
	}
	return maxResourceVersion;
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:58,代码来源:DeploymentWatcher.java

示例8: watchSeldonMLDeployments

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public int watchSeldonMLDeployments(int resourceVersion,int resourceVersionProcessed) throws ApiException, JsonProcessingException, IOException
{
	String rs = null;
	if (resourceVersion > 0)
		rs = ""+resourceVersion;
	logger.debug("Watching with rs "+rs);
	ApiClient client = Config.defaultClient();
	CustomObjectsApi api = new CustomObjectsApi(client);
	Watch<Object> watch = Watch.createWatch(
			client,
               api.listNamespacedCustomObjectCall("machinelearning.seldon.io", "v1alpha1", "default", "seldondeployments", null, null, rs, true, null, null),
               new TypeToken<Watch.Response<Object>>(){}.getType());
	
	int maxResourceVersion = resourceVersion;
	try{
       for (Watch.Response<Object> item : watch) {
       	Gson gson = new GsonBuilder().create();
   		String jsonInString = gson.toJson(item.object);
    	logger.debug(String.format("%s\n : %s%n", item.type, jsonInString));
   		ObjectMapper mapper = new ObjectMapper();
   	    JsonFactory factory = mapper.getFactory();
   	    JsonParser parser = factory.createParser(jsonInString);
   	    JsonNode actualObj = mapper.readTree(parser);
   	    if (actualObj.has("kind") && actualObj.get("kind").asText().equals("Status"))
   	    {
   	    	logger.warn("Possible old resource version found - resetting");
   	    	return 0;
   	    }
   	    else
   	    {
   	    	int resourceVersionNew = actualObj.get("metadata").get("resourceVersion").asInt();
   	    	if (resourceVersionNew <= resourceVersionProcessed)
   	    	{
   	    		logger.warn("Looking at already processed request - skipping");
   	    	}
   	    	else
   	    	{
   	    		if (resourceVersionNew > maxResourceVersion)
       	    		maxResourceVersion = resourceVersionNew;

   	    		this.processWatch(SeldonDeploymentUtils.jsonToSeldonDeployment(jsonInString), item.type);
   	    	}
   	    }
       }
	}
	catch(RuntimeException e)
	{
		if (e.getCause() instanceof SocketTimeoutException)
			return maxResourceVersion;
		else
			throw e;
	}
	finally {
	    watch.close();
	}
	return maxResourceVersion;
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:58,代码来源:SeldonDeploymentWatcher.java

示例9: SubsetStatus

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public SubsetStatus(String expectedJson, String returnedJson) throws Exception {

		this.expectedJson = expectedJson;
		this.returnedJson = returnedJson;

		// Used for JSON comparisons.
		mapper = new ObjectMapper();
		factory = mapper.getFactory();

		isSubset = isJsonSubset(expectedJson, returnedJson);

		message = compileMessage();
	}
 
开发者ID:eclipse,项目名称:scanning,代码行数:14,代码来源:SubsetStatus.java


注:本文中的com.fasterxml.jackson.databind.ObjectMapper.getFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。