本文整理汇总了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();
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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"));
}
示例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;
}
示例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;
}
示例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();
}