Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Client(@NotNull AuthProvider authProvider, @NotNull final HttpClient http

public Client(@NotNull AuthProvider authProvider, @NotNull HttpExecutor http) {
this.authProvider = authProvider;
this.mapper = JsonHelper.createMapper();
this.mapper = JsonHelper.mapper;
this.http = http;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected Link getAuthUncached(@NotNull Operation operation) throws IOException,
if (exitValue != 0) {
throw new IOException("Command returned with non-zero exit code " + exitValue + ": " + Arrays.toString(builder.command().toArray()));
}
return JsonHelper.createMapper().readValue(stdoutData.toByteArray(), Link.class);
return JsonHelper.mapper.readValue(stdoutData.toByteArray(), Link.class);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.testng.Assert;
import org.testng.annotations.Test;
import ru.bozaro.gitlfs.common.JsonHelper;
import ru.bozaro.gitlfs.common.data.*;
import ru.bozaro.gitlfs.common.data.Error;
import ru.bozaro.gitlfs.common.data.*;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -44,7 +44,7 @@ private void batchUpload(@NotNull String path) throws IOException {
new Meta("1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d550b648afa", 3)
)
));
Assert.assertEquals(JsonHelper.toString(result), JsonHelper.toString(new BatchRes(
Assert.assertEquals(JsonHelper.mapper.writeValueAsString(result), JsonHelper.mapper.writeValueAsString(new BatchRes(
Arrays.asList(
new BatchItem(
new Meta("b810bbe954d51e380f395de0c301a0a42d16f115453f2feb4188ca9f7189074e", 28),
Expand Down Expand Up @@ -104,7 +104,7 @@ private void batchDownload(@NotNull String path) throws IOException {
new Meta("1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d550b648afa", 3)
)
));
Assert.assertEquals(JsonHelper.toString(result), JsonHelper.toString(new BatchRes(
Assert.assertEquals(JsonHelper.mapper.writeValueAsString(result), JsonHelper.mapper.writeValueAsString(new BatchRes(
Arrays.asList(
new BatchItem(
new Meta("b810bbe954d51e380f395de0c301a0a42d16f115453f2feb4188ca9f7189074e", 28),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.bozaro.gitlfs.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -17,15 +16,11 @@
* @author Artem V. Navrotskiy
*/
public final class JsonHelper {
private JsonHelper() {
}

/**
* Creating mapper for serialize/deserialize data to JSON.
*/
@NotNull
public static ObjectMapper createMapper() {
final ObjectMapper mapper = new ObjectMapper();
public static final ObjectMapper mapper = new ObjectMapper();

static {
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setDateFormat(new StdDateFormat());
Expand All @@ -36,17 +31,8 @@ public static ObjectMapper createMapper() {
.withObjectIndenter(new DefaultIndenter(" ", "\n")));

mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}

/**
* Convert object to string.
*
* @param data Object.
* @return JSON data.
*/
@NotNull
public static String toString(@NotNull Object data) throws JsonProcessingException {
return createMapper().writeValueAsString(data);
private JsonHelper() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.jetbrains.annotations.Nullable;
import ru.bozaro.gitlfs.common.Constants;
import ru.bozaro.gitlfs.common.JsonHelper;
import ru.bozaro.gitlfs.common.data.*;
import ru.bozaro.gitlfs.common.data.Error;
import ru.bozaro.gitlfs.common.data.*;
import ru.bozaro.gitlfs.server.internal.ObjectResponse;
import ru.bozaro.gitlfs.server.internal.ResponseWriter;

Expand Down Expand Up @@ -60,7 +60,7 @@ public PointerServlet(@NotNull ContentManager manager, @NotNull String contentLo

public PointerServlet(@NotNull PointerManager manager) {
this.manager = manager;
this.mapper = JsonHelper.createMapper();
this.mapper = JsonHelper.mapper;
this.accessCheckerVisitor = new AccessCheckerVisitor(manager);
}

Expand Down Expand Up @@ -135,7 +135,7 @@ protected void doPost(@NotNull HttpServletRequest req, @NotNull HttpServletRespo
} catch (ServerError e) {
resp.setStatus(e.getStatusCode());
resp.setContentType(Constants.MIME_LFS_JSON);
JsonHelper.createMapper().writeValue(resp.getOutputStream(), new Error(e.getStatusCode(), e.getMessage()));
JsonHelper.mapper.writeValue(resp.getOutputStream(), new Error(e.getStatusCode(), e.getMessage()));
return;
}
super.doPost(req, resp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public ObjectResponse(int status, @NotNull Object value) {
public void write(@NotNull HttpServletResponse response) throws IOException {
response.setStatus(status);
response.setContentType(MIME_LFS_JSON);
JsonHelper.createMapper().writeValue(response.getOutputStream(), value);
JsonHelper.mapper.writeValue(response.getOutputStream(), value);
}
}