From f5028f5846e35b111c23707453559d5f2216b1a3 Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Tue, 30 Apr 2024 16:44:53 +0400 Subject: [PATCH] feat(bindings): use parents in serde https://github.com/asyncapi/jasyncapi/issues/184 --- .../bindings/ChannelBindingsDeserializer.java | 2 +- .../bindings/MessageBindingsDeserializer.java | 2 +- .../bindings/OperationBindingsDeserializer.java | 2 +- .../bindings/ServerBindingsDeserializer.java | 2 +- .../bindings/mqtt/MQTTChannelBinding.java | 17 +++++++++++++++++ .../bindings/mqtt/MQTTMessageBinding.java | 17 +++++++++++++++++ .../bindings/mqtt/MQTTOperationBinding.java | 17 +++++++++++++++++ .../bindings/mqtt/MQTTServerBinding.java | 17 +++++++++++++++++ 8 files changed, 72 insertions(+), 4 deletions(-) diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/ChannelBindingsDeserializer.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/ChannelBindingsDeserializer.java index bd8057ec..05f35de4 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/ChannelBindingsDeserializer.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/ChannelBindingsDeserializer.java @@ -9,7 +9,7 @@ import com.asyncapi.bindings.jms.JMSChannelBinding; import com.asyncapi.bindings.kafka.KafkaChannelBinding; import com.asyncapi.bindings.mercure.MercureChannelBinding; -import com.asyncapi.bindings.mqtt.v0._1_0.channel.MQTTChannelBinding; +import com.asyncapi.bindings.mqtt.MQTTChannelBinding; import com.asyncapi.bindings.mqtt5.MQTT5ChannelBinding; import com.asyncapi.bindings.nats.NATSChannelBinding; import com.asyncapi.bindings.pulsar.PulsarChannelBinding; diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/MessageBindingsDeserializer.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/MessageBindingsDeserializer.java index 138328df..3c03744b 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/MessageBindingsDeserializer.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/MessageBindingsDeserializer.java @@ -9,7 +9,7 @@ import com.asyncapi.bindings.jms.JMSMessageBinding; import com.asyncapi.bindings.kafka.KafkaMessageBinding; import com.asyncapi.bindings.mercure.MercureMessageBinding; -import com.asyncapi.bindings.mqtt.v0._1_0.message.MQTTMessageBinding; +import com.asyncapi.bindings.mqtt.MQTTMessageBinding; import com.asyncapi.bindings.mqtt5.MQTT5MessageBinding; import com.asyncapi.bindings.nats.NATSMessageBinding; import com.asyncapi.bindings.pulsar.PulsarMessageBinding; diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/OperationBindingsDeserializer.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/OperationBindingsDeserializer.java index 2aa5cbd7..995e3272 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/OperationBindingsDeserializer.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/OperationBindingsDeserializer.java @@ -9,7 +9,7 @@ import com.asyncapi.bindings.jms.JMSOperationBinding; import com.asyncapi.bindings.kafka.KafkaOperationBinding; import com.asyncapi.bindings.mercure.MercureOperationBinding; -import com.asyncapi.bindings.mqtt.v0._1_0.operation.MQTTOperationBinding; +import com.asyncapi.bindings.mqtt.MQTTOperationBinding; import com.asyncapi.bindings.mqtt5.MQTT5OperationBinding; import com.asyncapi.bindings.nats.NATSOperationBinding; import com.asyncapi.bindings.pulsar.PulsarOperationBinding; diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/ServerBindingsDeserializer.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/ServerBindingsDeserializer.java index 06b734cb..8ee2a09a 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/ServerBindingsDeserializer.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/ServerBindingsDeserializer.java @@ -9,7 +9,7 @@ import com.asyncapi.bindings.jms.JMSServerBinding; import com.asyncapi.bindings.kafka.KafkaServerBinding; import com.asyncapi.bindings.mercure.MercureServerBinding; -import com.asyncapi.bindings.mqtt.v0._1_0.server.MQTTServerBinding; +import com.asyncapi.bindings.mqtt.MQTTServerBinding; import com.asyncapi.bindings.mqtt5.MQTT5ServerBinding; import com.asyncapi.bindings.nats.NATSServerBinding; import com.asyncapi.bindings.pulsar.PulsarServerBinding; diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTChannelBinding.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTChannelBinding.java index a509c2cb..ccc41d93 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTChannelBinding.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTChannelBinding.java @@ -1,6 +1,9 @@ package com.asyncapi.bindings.mqtt; import com.asyncapi.bindings.ChannelBinding; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.EqualsAndHashCode; /** * This class MUST NOT contain any properties. Its name is reserved for future use. @@ -11,4 +14,18 @@ * @see MQTT channel binding * @author Pavel Bodiachevskii */ +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + defaultImpl = com.asyncapi.bindings.mqtt.v0._1_0.channel.MQTTChannelBinding.class, + property = "bindingVersion", + visible = true +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = com.asyncapi.bindings.mqtt.v0._1_0.channel.MQTTChannelBinding.class, names = { + "0.1.0", + "latest" + }), +}) +@EqualsAndHashCode(callSuper = true) public abstract class MQTTChannelBinding extends ChannelBinding {} \ No newline at end of file diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTMessageBinding.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTMessageBinding.java index ce8fe322..e1d8cdfa 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTMessageBinding.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTMessageBinding.java @@ -1,6 +1,9 @@ package com.asyncapi.bindings.mqtt; import com.asyncapi.bindings.MessageBinding; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.EqualsAndHashCode; /** * Describes MQTT message binding. @@ -11,4 +14,18 @@ * @see MQTT message binding * @author Pavel Bodiachevskii */ +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + defaultImpl = com.asyncapi.bindings.mqtt.v0._1_0.message.MQTTMessageBinding.class, + property = "bindingVersion", + visible = true +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = com.asyncapi.bindings.mqtt.v0._1_0.message.MQTTMessageBinding.class, names = { + "0.1.0", + "latest" + }), +}) +@EqualsAndHashCode(callSuper = true) public abstract class MQTTMessageBinding extends MessageBinding {} \ No newline at end of file diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTOperationBinding.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTOperationBinding.java index efc12256..580cf77a 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTOperationBinding.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTOperationBinding.java @@ -1,6 +1,9 @@ package com.asyncapi.bindings.mqtt; import com.asyncapi.bindings.OperationBinding; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.EqualsAndHashCode; /** * Describes MQTT operation binding. @@ -11,4 +14,18 @@ * @see MQTT operation binding * @author Pavel Bodiachevskii */ +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + defaultImpl = com.asyncapi.bindings.mqtt.v0._1_0.operation.MQTTOperationBinding.class, + property = "bindingVersion", + visible = true +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = com.asyncapi.bindings.mqtt.v0._1_0.operation.MQTTOperationBinding.class, names = { + "0.1.0", + "latest" + }), +}) +@EqualsAndHashCode(callSuper = true) public abstract class MQTTOperationBinding extends OperationBinding {} \ No newline at end of file diff --git a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTServerBinding.java b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTServerBinding.java index 1156b2ac..2002ecdd 100644 --- a/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTServerBinding.java +++ b/asyncapi-core/src/main/java/com/asyncapi/bindings/mqtt/MQTTServerBinding.java @@ -1,6 +1,9 @@ package com.asyncapi.bindings.mqtt; import com.asyncapi.bindings.ServerBinding; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.EqualsAndHashCode; /** * Describes MQTT server binding. @@ -11,4 +14,18 @@ * @see MQTT server binding * @author Pavel Bodiachevskii */ +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXISTING_PROPERTY, + defaultImpl = com.asyncapi.bindings.mqtt.v0._1_0.server.MQTTServerBinding.class, + property = "bindingVersion", + visible = true +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = com.asyncapi.bindings.mqtt.v0._1_0.server.MQTTServerBinding.class, names = { + "0.1.0", + "latest" + }), +}) +@EqualsAndHashCode(callSuper = true) public abstract class MQTTServerBinding extends ServerBinding {} \ No newline at end of file