summaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-06 09:18:05 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-06 09:18:05 +0100
commit8c38e6ca614b22c39ef2fca549d9eb2265304baa (patch)
treecf59d24d6005307f8d24579026c7bf48cb986d5c /src/main/java/io
parentbd2208922ea6a0486074c72a57b01d7df368f885 (diff)
downloadrules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.tar.gz
rules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.tar.bz2
rules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.tar.xz
rules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.zip
Better serializer for CIDRs too.
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/trygvis/rules/network/Ipv4Cidr.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java b/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java
index 34b3a0b..6e1dde9 100644
--- a/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java
+++ b/src/main/java/io/trygvis/rules/network/Ipv4Cidr.java
@@ -1,10 +1,17 @@
package io.trygvis.rules.network;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
+@JsonSerialize(using = Ipv4Cidr.Serializer.class)
public class Ipv4Cidr {
public final int network;
public final int netmask;
@@ -37,4 +44,13 @@ public class Ipv4Cidr {
return addresses;
}
+
+ public static class Serializer extends JsonSerializer<Ipv4Cidr> {
+ @Override
+ public void serialize(Ipv4Cidr value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
+ gen.writeStartObject();
+ gen.writeObjectField("value", value.toString());
+ gen.writeEndObject();
+ }
+ }
}