com.vmware.xenon.common.Utils.fromJson()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中com.vmware.xenon.common.Utils.fromJson()方法的一些代码示例,展示了Utils.fromJson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.fromJson()方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:fromJson

Utils.fromJson介绍

暂无

代码示例

代码示例来源:origin: vmware/admiral

public JsonObject getAsJsonObject() {
  if (jsonObject == null) {
    jsonObject = Utils.fromJson(jsonSerializedState, JsonObject.class);
  }
  return jsonObject;
}

代码示例来源:origin: vmware/admiral

@SuppressWarnings("unchecked")
public static List<String> getAffinityNames(ComputeDescriptionService.ComputeDescription desc) {
  if (desc.customProperties == null) {
    return Collections.emptyList();
  }
  String affinitiesAsString = desc.customProperties
      .getOrDefault(CUSTOM_PROP_NAME_AFFINITY, "");
  return Utils.fromJson(affinitiesAsString, List.class);
}

代码示例来源:origin: vmware/xenon

public QueryElementResult<T> result(Object json, long count) {
  QueryElementResult<T> r = new QueryElementResult<>();
  r.result = Utils.fromJson(json, this.type);
  r.documentSelfLink = r.result.documentSelfLink;
  r.count = count;
  return r;
}

代码示例来源:origin: vmware/admiral

@Override
public void updateServiceDocument(ServiceDocument serviceDocument) {
  super.updateServiceDocument(serviceDocument);
  this.commonDescription = Utils.fromJson(componentJson,
      CommonReservationResourceDescription.class);
}

代码示例来源:origin: vmware/admiral

private void visitPlacementHostSelectionTaskStage(TaskServiceStageWithLink stage) {
    if (stage.taskSubStage.equals(DefaultSubStage.COMPLETED.name())) {
      info.hostSelections = Utils.fromJson(stage.properties,
          PlacementHostSelectionTaskState.class).hostSelections;
    }
  }
}

代码示例来源:origin: vmware/admiral

public boolean accepts(TaskServiceStageWithLink stage) {
  if (stage.documentSelfLink.startsWith(RequestBrokerFactoryService.SELF_LINK)
      && stage.taskSubStage.equals(RequestBrokerState.SubStage.COMPLETED.name())) {
    RequestBrokerState state = Utils.fromJson(stage.properties,
        RequestBrokerState.class);
    return ResourceType.CONTAINER_TYPE.getName().equals(state.resourceType);
  }
  return false;
}

代码示例来源:origin: vmware/xenon

private boolean isMigrationFinishNotice(Operation patch) {
  if (patch.getBodyRaw() instanceof String) {
    MigrationFinishedNotice doc = Utils.fromJson(patch.getBodyRaw(), MigrationFinishedNotice.class);
    return MigrationFinishedNotice.KIND.equals(doc.documentKind);
  }
  return patch.getBodyRaw() instanceof MigrationFinishedNotice;
}

代码示例来源:origin: vmware/xenon

public static HashMap<String, ExampleServiceState> queryResultToExampleState(
    ServiceDocumentQueryResult r) {
  HashMap<String, ExampleServiceState> state = new HashMap<>();
  for (String k : r.documents.keySet()) {
    state.put(k, Utils.fromJson(r.documents.get(k), ExampleServiceState.class));
  }
  return state;
}

代码示例来源:origin: vmware/xenon

public FindForLink(ServiceDocument document) {
  this.selfLink = document.documentSelfLink;
  String s = Utils.toJson(document);
  this.json = Utils.fromJson(s, JsonObject.class);
  this.documentClass = document.getClass().getName();
}

代码示例来源:origin: com.vmware.xenon/xenon-common

@SuppressWarnings("unchecked")
public static <T> void assertSerializationPreservesObjects(T instance,
    BiFunction<T, T, Void> comp) {
  String json = Utils.toJson(instance);
  T deserialized = (T) Utils.fromJson(json, instance.getClass());
  comp.apply(instance, deserialized);
}

代码示例来源:origin: vmware/xenon

@Test
public void testParseZonedDateTime() throws Exception {
  Calendar cal = Calendar.getInstance();
  cal.setTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
  cal.set(2013, 4, 30, 23, 38, 27);
  cal.set(Calendar.MILLISECOND, 85);
  ZoneId zid = ZoneId.of("Australia/Sydney");
  ZonedDateTime expected = ZonedDateTime.ofInstant(cal.toInstant(), zid);
  ZonedDateTime actual = Utils.fromJson(
      "\"2013-05-30T23:38:27.085+10:00[Australia/Sydney]\"", ZonedDateTime.class);
  assertEquals(expected, actual);
}

代码示例来源:origin: vmware/xenon

private void handleEventStreamError(Operation op, ServerSentEvent event) {
  String errorMsg = String.format("Service %s returned error for %s. id %d",
      op.getUri(), op.getAction(), op.getId());
  ServiceErrorResponse rsp = Utils.fromJson(event.data, ServiceErrorResponse.class);
  errorMsg += " message " + rsp.message;
  op.setBodyNoCloning(rsp);
  op.fail(new ProtocolException(errorMsg));
}

代码示例来源:origin: vmware/xenon

@Test
public void testParseJsonWhenMapWithValueTypeObject() throws Exception {
  TestKeyObjectValueHolder testHolder = Utils.fromJson(
      "{\"keyValues\":{\"prop1\":\"value1\"}}", TestKeyObjectValueHolder.class);
  assertEquals("value1", testHolder.keyValues.get("prop1"));
}

代码示例来源:origin: vmware/xenon

@Test
public void testFactoryPostWithoutId() throws Throwable {
  ServiceDocumentQueryResult res = createInstances(SERVICE_COUNT, true);
  assertTrue(res.documentLinks.size() == SERVICE_COUNT);
  assertTrue(res.documentLinks.size() == res.documents.size());
  for (Object s : res.documents.values()) {
    TenantService.TenantState state = Utils.fromJson(s, TenantService.TenantState.class);
    assertNotNull(state.id);
  }
}

代码示例来源:origin: vmware/xenon

private String waitForStatus(VerificationHost peer,
               Function<SynchronizationManagementState.Status, Boolean> f) {
  SynchronizationManagementState[] state = new SynchronizationManagementState[1];
  URI serviceUri = UriUtils.buildUri(peer, SynchronizationManagementService.class);
  peer.waitFor("Wait for the required status failed", () -> {
    Operation op = this.sender.sendAndWait(Operation.createGet(serviceUri));
    ServiceDocumentQueryResult result = op.getBody(ServiceDocumentQueryResult.class);
    state[0] = Utils.fromJson(result.documents.get(ExampleService.FACTORY_LINK), SynchronizationManagementState.class);
    return f.apply(state[0].status);
  });
  return state[0].owner;
}

代码示例来源:origin: vmware/xenon

@Override
  public void handlePost(Operation postOperation) {
    MigrationTaskService.TransformRequest request = postOperation.getBody(MigrationTaskService.TransformRequest.class);
    ExampleServiceState state = Utils.fromJson(request.originalDocument, ExampleServiceState.class);
    state.name = state.name + "-transformed-v2";
    MigrationTaskService.TransformResponse response = new MigrationTaskService.TransformResponse();
    response.destinationLinks = new HashMap<>();
    response.destinationLinks.put(Utils.toJson(state), request.destinationLink);
    postOperation.setBody(response).complete();
  }
}

代码示例来源:origin: com.vmware.xenon/xenon-common

private String waitForStatus(VerificationHost peer,
               Function<SynchronizationManagementState.Status, Boolean> f) {
  SynchronizationManagementState[] state = new SynchronizationManagementState[1];
  URI serviceUri = UriUtils.buildUri(peer, SynchronizationManagementService.class);
  peer.waitFor("Wait for the required status failed", () -> {
    Operation op = this.sender.sendAndWait(Operation.createGet(serviceUri));
    ServiceDocumentQueryResult result = op.getBody(ServiceDocumentQueryResult.class);
    state[0] = Utils.fromJson(result.documents.get(ExampleService.FACTORY_LINK), SynchronizationManagementState.class);
    return f.apply(state[0].status);
  });
  return state[0].owner;
}

代码示例来源:origin: vmware/xenon

@Test
public void testCustomConfigurationForClass() {
  SomeDocument1 doc = new SomeDocument1();
  doc.value = new SomeComplexObject("fred", "barney");
  String json = Utils.toJson(doc);
  JsonElement expected = readJson("{ \"value\": \"fred|barney\" "
      + BORING_JSON_DOC_BITS + "}");
  assertEquals(expected, readJson(json));
  SomeDocument1 docBack = Utils.fromJson(json, SomeDocument1.class);
  assertComplexObjectEquals(doc.value, docBack.value);
}

代码示例来源:origin: com.vmware.xenon/xenon-common

@Test
public void testCustomConfigurationForClass() {
  SomeDocument1 doc = new SomeDocument1();
  doc.value = new SomeComplexObject("fred", "barney");
  String json = Utils.toJson(doc);
  JsonElement expected = readJson("{ \"value\": \"fred|barney\" "
      + BORING_JSON_DOC_BITS + "}");
  assertEquals(expected, readJson(json));
  SomeDocument1 docBack = Utils.fromJson(json, SomeDocument1.class);
  assertComplexObjectEquals(doc.value, docBack.value);
}

代码示例来源:origin: vmware/xenon

@Test
public void testCustomConfigurationParaemeterizedType() {
  SomeDocument2<SomeComplexObject> doc = new SomeDocument2<SomeComplexObject>();
  doc.value = new SomeComplexObject("fred", "barney");
  String json = Utils.toJson(doc);
  JsonElement expected = readJson("{ \"value\": \"barney&fred\" "
      + BORING_JSON_DOC_BITS + "}");
  assertEquals(expected, readJson(json));
  Type someDocType2 = new TypeToken<SomeDocument2<SomeComplexObject>>() {}.getType();
  SomeDocument2<SomeComplexObject> docBack = Utils.fromJson(json, someDocType2);
  assertComplexObjectEquals(doc.value, docBack.value);
}

相关文章