use of com.thoughtworks.go.util.json.JsonUrl in project gocd by gocd.
the class DirectoryEntry method toJson.
@Override
public Map<String, Object> toJson() {
Map<String, Object> fileOrFolder = new LinkedHashMap<>();
fileOrFolder.put("name", fileName);
fileOrFolder.put("url", new JsonUrl(url));
fileOrFolder.put("type", type);
return fileOrFolder;
}
use of com.thoughtworks.go.util.json.JsonUrl in project gocd by gocd.
the class JsonViewTest method testShouldRenderUrlsWithContext.
@Test
public void testShouldRenderUrlsWithContext() {
JsonUrl url = new JsonUrl("/foo/bar/baz");
when(requestContext.getFullRequestPath()).thenReturn("http://something/context");
String json = render(url, requestContext);
assertThat(json, is("\"http://something/context/foo/bar/baz\""));
}
use of com.thoughtworks.go.util.json.JsonUrl in project gocd by gocd.
the class JsonRenderer method gsonBuilder.
private static Gson gsonBuilder(final GoRequestContext requestContext) {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(JsonUrl.class, (JsonSerializer<JsonUrl>) (src, typeOfSrc, context) -> {
if (requestContext == null) {
return new JsonPrimitive(src.getUrl());
} else {
return new JsonPrimitive(requestContext.getFullRequestPath() + src.getUrl());
}
});
builder.registerTypeHierarchyAdapter(MessageSourceResolvable.class, (JsonSerializer<MessageSourceResolvable>) (src, typeOfSrc, context) -> {
if (requestContext == null) {
return new JsonPrimitive(src.getDefaultMessage());
} else {
return new JsonPrimitive(requestContext.getMessage(src));
}
});
builder.serializeNulls();
return builder.create();
}
Aggregations