@Test(dataProvider = "serializeDP") public void serialize(Path path, String expectedPathAsJson) { assertEquals(testling.serialize(path, Path.class, null).getAsString(), expectedPathAsJson); }
@Override public JsonElement serialize(final Path src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonPrimitive(StringUtils.EMPTY); } final Path normalized = src.toAbsolutePath().normalize(); Path relativePath = basePath.relativize(normalized); LOGGER.debug("Relativized Path: '{}' => '{}'", normalized, relativePath); return new JsonPrimitive(relativePath.toString()); }
PathSerializer implements JsonSerializer<Path> { @Override public JsonElement serialize(final Path src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonPrimitive(StringUtils.EMPTY); } final Path normalized = src.toAbsolutePath().normalize(); Path relativePath = basePath.relativize(normalized); LOGGER.debug("Relativized Path: '{}' => '{}'", normalized, relativePath); return new JsonPrimitive(relativePath.toString()); } }
PathSerializer implements JsonSerializer<Path> { @Override public JsonElement serialize(final Path src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonPrimitive(StringUtils.EMPTY); } final Path normalized = src.toAbsolutePath().normalize(); Path relativePath = basePath.relativize(normalized); LOGGER.debug("Relativized Path: '{}' => '{}'", normalized, relativePath); return new JsonPrimitive(relativePath.toString()); } PathSerializer(Path basePath); }
PathSerializer implements JsonSerializer<Path> { @Override public JsonElement serialize(final Path src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonPrimitive(StringUtils.EMPTY); } final Path normalized = src.toAbsolutePath().normalize(); Path relativePath = basePath.relativize(normalized); LOGGER.debug("Relativized Path: '{}' => '{}'", normalized, relativePath); return new JsonPrimitive(relativePath.toString()); } PathSerializer(Path basePath); @Override JsonElement serialize(final Path src, final Type typeOfSrc, final JsonSerializationContext context); }
PathSerializer implements JsonSerializer<Path> { @Override public JsonElement serialize(final Path src, final Type typeOfSrc, final JsonSerializationContext context) { if (src == null) { return new JsonPrimitive(StringUtils.EMPTY); } final Path normalized = src.toAbsolutePath().normalize(); Path relativePath = basePath.relativize(normalized); LOGGER.debug("Relativized Path: '{}' => '{}'", normalized, relativePath); return new JsonPrimitive(relativePath.toString()); } PathSerializer(Path basePath); @Override JsonElement serialize(final Path src, final Type typeOfSrc, final JsonSerializationContext context);  }