[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/release] Configure Jackson using class annotations.
commit 52494a7f343baa1d0ae84078ad23dac52e616c1d
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed Jul 11 21:49:40 2018 +0200
Configure Jackson using class annotations.
---
src/main/java/org/torproject/onionoo/docs/Document.java | 15 +++++++++++++++
.../java/org/torproject/onionoo/docs/DocumentStore.java | 10 +---------
.../org/torproject/onionoo/server/ResponseBuilder.java | 10 +---------
.../torproject/onionoo/server/ResourceServletTest.java | 12 ++++--------
.../onionoo/writer/GraphHistoryCompilerTest.java | 10 +---------
5 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/Document.java b/src/main/java/org/torproject/onionoo/docs/Document.java
index 54bb0d5..9d8d484 100644
--- a/src/main/java/org/torproject/onionoo/docs/Document.java
+++ b/src/main/java/org/torproject/onionoo/docs/Document.java
@@ -3,6 +3,21 @@
package org.torproject.onionoo.docs;
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import com.fasterxml.jackson.databind.annotation.JsonNaming;
+
+/* Use snake_case for naming fields rather than camelCase. */
+@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
+/* Exclude fields that are null or empty. */
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+/* Only consider fields, no getters, setters, or constructors. */
+@JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE,
+ fieldVisibility = JsonAutoDetect.Visibility.ANY,
+ getterVisibility = JsonAutoDetect.Visibility.NONE,
+ isGetterVisibility = JsonAutoDetect.Visibility.NONE,
+ setterVisibility = JsonAutoDetect.Visibility.NONE)
public abstract class Document {
private transient String documentString;
diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
index e474684..b044788 100644
--- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
+++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
@@ -5,12 +5,8 @@ package org.torproject.onionoo.docs;
import org.torproject.onionoo.util.FormattingUtils;
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,11 +40,7 @@ public class DocumentStore {
private static Logger log = LoggerFactory.getLogger(
DocumentStore.class);
- private static ObjectMapper objectMapper = new ObjectMapper()
- .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
- .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
- .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
- .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
+ private static ObjectMapper objectMapper = new ObjectMapper();
private final File statusDir = new File("status");
diff --git a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
index decf559..241b3bd 100644
--- a/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
+++ b/src/main/java/org/torproject/onionoo/server/ResponseBuilder.java
@@ -14,12 +14,8 @@ import org.torproject.onionoo.docs.UptimeDocument;
import org.torproject.onionoo.docs.WeightsDocument;
import org.torproject.onionoo.util.FormattingUtils;
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,11 +31,7 @@ public class ResponseBuilder {
private static final Logger logger =
LoggerFactory.getLogger(ResponseBuilder.class);
- private static ObjectMapper objectMapper = new ObjectMapper()
- .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
- .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
- .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
- .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
+ private static ObjectMapper objectMapper = new ObjectMapper();
private DocumentStore documentStore;
private String buildRevision;
diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
index 145619d..2bc8203 100644
--- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
+++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
@@ -14,10 +14,7 @@ import org.torproject.onionoo.docs.DummyDocumentStore;
import org.torproject.onionoo.docs.UpdateStatus;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.junit.Before;
import org.junit.Test;
@@ -39,11 +36,7 @@ import java.util.TreeSet;
* which tests servlet specifics. */
public class ResourceServletTest {
- private static ObjectMapper objectMapper = new ObjectMapper()
- .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
- .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
- .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
- .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
+ private static ObjectMapper objectMapper = new ObjectMapper();
private SortedMap<String, org.torproject.onionoo.docs.SummaryDocument> relays;
private SortedMap<String, org.torproject.onionoo.docs.SummaryDocument>
@@ -357,6 +350,7 @@ public class ResourceServletTest {
}
@SuppressWarnings("MemberName")
+ @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
private static class SummaryDocument {
private String version;
private String next_major_version_scheduled;
@@ -372,6 +366,7 @@ public class ResourceServletTest {
}
@SuppressWarnings("MemberName")
+ @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
private static class RelaySummary {
private String n;
private String f;
@@ -380,6 +375,7 @@ public class ResourceServletTest {
}
@SuppressWarnings("MemberName")
+ @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
private static class BridgeSummary {
private String n;
private String h;
diff --git a/src/test/java/org/torproject/onionoo/writer/GraphHistoryCompilerTest.java b/src/test/java/org/torproject/onionoo/writer/GraphHistoryCompilerTest.java
index b055426..aa091de 100644
--- a/src/test/java/org/torproject/onionoo/writer/GraphHistoryCompilerTest.java
+++ b/src/test/java/org/torproject/onionoo/writer/GraphHistoryCompilerTest.java
@@ -9,11 +9,7 @@ import static org.junit.Assert.assertNotNull;
import org.torproject.onionoo.docs.DateTimeHelper;
import org.torproject.onionoo.docs.GraphHistory;
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,11 +26,7 @@ import java.util.Map;
@RunWith(Parameterized.class)
public class GraphHistoryCompilerTest {
- private static ObjectMapper objectMapper = new ObjectMapper()
- .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
- .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
- .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
- .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
+ private static ObjectMapper objectMapper = new ObjectMapper();
/** Provide test data. */
@Parameters
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits