@Override public String toString() { return Utils.toJson(this); } }
@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)); }
public void updateServiceDocument(ServiceDocument serviceDocument) { this.componentJson = Utils.toJson(serviceDocument); this.component = serviceDocument; } }
@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)); }
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); }
@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); }
private Object removeFactoryPathFromSelfLink(Object jsonObject, String factoryPath) { String selfLink = extractId(jsonObject, factoryPath); return Utils.toJson( Utils.setJsonProperty(jsonObject, ServiceDocument.FIELD_NAME_SELF_LINK, selfLink)); }
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(); }
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(); }
@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); }
@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)); }
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()); } }
@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(); } }
@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(); } }
@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(); } }
@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); }
@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(); } };
@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); }
@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); }
@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); }