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

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

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

Utils.toJson介绍

[英]Outputs body to a JSON String format based on the provided JSON options
[中]根据提供的JSON选项将正文输出为JSON字符串格式

代码示例

代码示例来源:origin: com.vmware.photon.controller/photon-vsphere-adapter-util

@Override
  public String toString() {
    return Utils.toJson(this);
  }
}

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

@Ignore("https://www.pivotaltracker.com/story/show/151532080 Fail on windows")
@Test
public void testPathJsonSerialization() {
  Path p = Paths.get("test");
  String jsonRepr = Utils.toJson(p);
  assertEquals("\"" + p.toAbsolutePath().toAbsolutePath() + "\"", jsonRepr);
  Arguments arguments = new Arguments();
  Logger.getAnonymousLogger().info(Utils.toJsonHtml(arguments));
}

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

public void updateServiceDocument(ServiceDocument serviceDocument) {
    this.componentJson = Utils.toJson(serviceDocument);
    this.component = serviceDocument;
  }
}

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

@Ignore("https://www.pivotaltracker.com/story/show/151532080 Fail on windows")
@Test
public void testPathJsonSerialization() {
  Path p = Paths.get("test");
  String jsonRepr = Utils.toJson(p);
  assertEquals("\"" + p.toAbsolutePath().toAbsolutePath() + "\"", jsonRepr);
  Arguments arguments = new Arguments();
  Logger.getAnonymousLogger().info(Utils.toJsonHtml(arguments));
}

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

protected void fail(AdapterRequest request, Operation o, Throwable e) {
  if (o != null && o.getBodyRaw() != null) {
    String errMsg = String.format("%s; Reason: %s", e.getMessage(),
        Utils.toJson(o.getBodyRaw()));
    e = new Exception(errMsg, e);
  }
  fail(request, e);
}

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

@Test
public void testPrettyPrinting() {
  SomeDocument1 doc = new SomeDocument1();
  doc.value = new SomeComplexObject("fred", "barney");
  String compact = Utils.toJson(doc);
  String pretty = Utils.toJsonHtml(doc);
  assertTrue(pretty.length() > compact.length());
  JsonElement prettyParsed = readJson(pretty);
  JsonElement compactParsed = readJson(compact);
  assertEquals(compactParsed, prettyParsed);
}

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

private Object removeFactoryPathFromSelfLink(Object jsonObject, String factoryPath) {
  String selfLink = extractId(jsonObject, factoryPath);
  return Utils.toJson(
      Utils.setJsonProperty(jsonObject, ServiceDocument.FIELD_NAME_SELF_LINK, selfLink));
}

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

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: 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: vmware/xenon

@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 testBinaryEncodedToBase64() throws Exception {
  BinaryHolder instance = new BinaryHolder();
  instance.picture = "ssdfgsdgsdg".getBytes();
  String base64encoded = Base64.getEncoder().encodeToString(instance.picture);
  String json = Utils.toJson(instance);
  assertTrue(json.contains(base64encoded));
}

代码示例来源:origin: com.github.tteky/xenon-ext-jaxrs

Object operationDecoder(Operation completedOp, MethodInfo httpMethod) {
  if (httpMethod.getType() instanceof ParameterizedType) {
    String json = Utils.toJson(completedOp.getBodyRaw());
    return Utils.fromJson(json, httpMethod.getType());
  } else {
    return completedOp.getBody(httpMethod.getReturnType());
  }
}

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

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

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

@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: 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: vmware/admiral

@Override
public void registerForServiceAvailability(Operation.CompletionHandler completion,
    String nodeSelectorPath, boolean checkReplica, String... servicePaths) {
  log("servicePaths %s: %s", checkReplica, Utils.toJson(servicePaths));
  if (enablePostgres && checkReplica) {
    PostgresHostUtils.registerForReplicatedServiceAvailability(this, completion,
        isStarted() ? getSystemAuthorizationContext() : null, nodeSelectorPath,
        servicePaths);
    return;
  }
  super.registerForServiceAvailability(completion, nodeSelectorPath, checkReplica, servicePaths);
}

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

@Override
  public void handleGet(Operation get) {
    ServiceDocument emptyDoc = new ServiceDocument();
    // stop this service to simulate the case that op has returned but target service is not in attachedService.
    getHost().stopService(this);
    // return a doc that doesn't have documentKind
    get.setBody(Utils.toJson(emptyDoc)).complete();
  }
};

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

@Test
public void TestNamespaceCorrectSerialize() {
  Namespace namespace = new Namespace();
  namespace.metadata = new ObjectMeta();
  String json = Utils.toJson(namespace);
  Namespace result = Utils.fromJson(json, Namespace.class);
  assertNotNull(result);
  assertNotNull(result.metadata);
}

代码示例来源: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 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);
}

相关文章