diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-06 09:18:05 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-06 09:18:05 +0100 |
commit | 8c38e6ca614b22c39ef2fca549d9eb2265304baa (patch) | |
tree | cf59d24d6005307f8d24579026c7bf48cb986d5c | |
parent | bd2208922ea6a0486074c72a57b01d7df368f885 (diff) | |
download | rules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.tar.gz rules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.tar.bz2 rules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.tar.xz rules-sandbox-8c38e6ca614b22c39ef2fca549d9eb2265304baa.zip |
Better serializer for CIDRs too.
-rw-r--r-- | out/phase-1.yaml | 5 | ||||
-rw-r--r-- | out/vpn0.yaml | 5 | ||||
-rw-r--r-- | src/main/java/io/trygvis/rules/network/Ipv4Cidr.java | 16 |
3 files changed, 18 insertions, 8 deletions
diff --git a/out/phase-1.yaml b/out/phase-1.yaml index 8c34f1a..b582087 100644 --- a/out/phase-1.yaml +++ b/out/phase-1.yaml @@ -321,10 +321,7 @@ data: --- type: "io.trygvis.rules.network.Ipv4Cidr" data: - network: -1062729216 - netmask: -8 - size: 8 - bits: 29 + value: "192.168.10.0/29" --- type: "io.trygvis.rules.terraform.ScalewayMachine" data: diff --git a/out/vpn0.yaml b/out/vpn0.yaml index 1c88e80..3fc6836 100644 --- a/out/vpn0.yaml +++ b/out/vpn0.yaml @@ -145,7 +145,4 @@ data: --- type: "io.trygvis.rules.network.Ipv4Cidr" data: - network: -1062729216 - netmask: -8 - size: 8 - bits: 29 + value: "192.168.10.0/29" 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(); + } + } } |