From 8c38e6ca614b22c39ef2fca549d9eb2265304baa Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 6 Jan 2021 09:18:05 +0100 Subject: Better serializer for CIDRs too. --- src/main/java/io/trygvis/rules/network/Ipv4Cidr.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/main/java/io') 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 { + @Override + public void serialize(Ipv4Cidr value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeObjectField("value", value.toString()); + gen.writeEndObject(); + } + } } -- cgit v1.2.3