diff --git a/src/main/java/io/zenwave360/modulith/events/scs/AvroEventSerializer.java b/src/main/java/io/zenwave360/modulith/events/scs/AvroEventSerializer.java index e94fc9e..3992cbe 100644 --- a/src/main/java/io/zenwave360/modulith/events/scs/AvroEventSerializer.java +++ b/src/main/java/io/zenwave360/modulith/events/scs/AvroEventSerializer.java @@ -1,12 +1,8 @@ package io.zenwave360.modulith.events.scs; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.avro.AvroMapper; -import org.apache.avro.generic.GenericRecord; -import org.apache.avro.specific.SpecificRecord; import org.springframework.modulith.events.core.EventSerializer; import java.util.Map; @@ -30,4 +26,5 @@ protected Map serializeToMap(Object payload) { objectNode.remove("specificData"); // TODO: remove this recursively return avroMapper.convertValue(objectNode, Map.class); } + } diff --git a/src/main/java/io/zenwave360/modulith/events/scs/MessageEventSerializer.java b/src/main/java/io/zenwave360/modulith/events/scs/MessageEventSerializer.java index 1c8c294..79ff6b6 100644 --- a/src/main/java/io/zenwave360/modulith/events/scs/MessageEventSerializer.java +++ b/src/main/java/io/zenwave360/modulith/events/scs/MessageEventSerializer.java @@ -15,6 +15,7 @@ import java.util.Map; public class MessageEventSerializer implements EventSerializer { + private final ObjectMapper jacksonMapper; public MessageEventSerializer(ObjectMapper jacksonMapper) { @@ -45,12 +46,14 @@ public Object serialize(Object event) { public T deserialize(Object serialized, Class type) { try { return unsafeDeserialize(serialized, type); - } catch (JsonProcessingException | ClassNotFoundException e) { + } + catch (JsonProcessingException | ClassNotFoundException e) { throw new RuntimeException(e); } } - private T unsafeDeserialize(Object serialized, Class type) throws JsonProcessingException, ClassNotFoundException { + private T unsafeDeserialize(Object serialized, Class type) + throws JsonProcessingException, ClassNotFoundException { if (Message.class.isAssignableFrom(type)) { JsonNode node = jacksonMapper.readTree(serialized.toString()); JsonNode headersNode = node.get("headers"); @@ -63,7 +66,8 @@ private T unsafeDeserialize(Object serialized, Class type) throws JsonPro objectNode.remove("_class"); } payload = deserializePayload(payloadNode, payloadType); - } else { + } + else { payload = deserializePayload(payloadNode, Object.class); } return (T) MessageBuilder.createMessage(payload, new MessageHeaders(headers)); @@ -79,7 +83,8 @@ protected Object jacksonSerialize(Object event) { try { var map = serializeToMap(event); return jacksonMapper.writeValueAsString(map); - } catch (JsonProcessingException e) { + } + catch (JsonProcessingException e) { throw new RuntimeException(e); } } @@ -88,8 +93,10 @@ protected T jacksonDeserialize(Object serialized, Class type) { try { JsonNode node = jacksonMapper.readTree(serialized.toString()); return (T) jacksonMapper.readerFor(type).readValue(node); - } catch (IOException e) { + } + catch (IOException e) { throw new RuntimeException(e); } } + } diff --git a/src/main/java/io/zenwave360/modulith/events/scs/SpringCloudStreamEventExternalizer.java b/src/main/java/io/zenwave360/modulith/events/scs/SpringCloudStreamEventExternalizer.java index 158aaf9..c37ac1b 100644 --- a/src/main/java/io/zenwave360/modulith/events/scs/SpringCloudStreamEventExternalizer.java +++ b/src/main/java/io/zenwave360/modulith/events/scs/SpringCloudStreamEventExternalizer.java @@ -25,12 +25,18 @@ public class SpringCloudStreamEventExternalizer implements BiFunction apply(RoutingTarget routingTarget, Object event) { var keyHeaderValue = routing.getKey(event); var keyHeaderName = getKeyHeaderName(target, bindingServiceProperties, binderFactory); - var headersMap = event instanceof Message ? new LinkedHashMap<>(((Message) event).getHeaders()) : new LinkedHashMap(); + var headersMap = event instanceof Message ? new LinkedHashMap<>(((Message) event).getHeaders()) + : new LinkedHashMap(); if (keyHeaderValue != null && keyHeaderName != null) { - if(!headersMap.containsKey(keyHeaderName)) { + if (!headersMap.containsKey(keyHeaderName)) { log.debug("Adding key header to message: {} = {}", keyHeaderName, keyHeaderValue); headersMap.put(keyHeaderName, keyHeaderValue); } } - var payload = event instanceof Message? ((Message) event).getPayload() : event; - var message = MessageBuilder.withPayload(payload) - .copyHeaders(headersMap) - .build(); + var payload = event instanceof Message ? ((Message) event).getPayload() : event; + var message = MessageBuilder.withPayload(payload).copyHeaders(headersMap).build(); log.debug("Sending event to Spring Cloud Stream target: {}", target); var result = streamBridge.send(target, message); @@ -70,23 +75,22 @@ public CompletableFuture apply(RoutingTarget routingTarget, Object event) { "org.springframework.cloud.stream.binder.pubsub.PubSubMessageChannelBinder", "pubsub_orderingKey", "org.springframework.cloud.stream.binder.eventhubs.EventHubsMessageChannelBinder", "partitionKey", "org.springframework.cloud.stream.binder.solace.SolaceMessageChannelBinder", "solace_messageKey", - "org.springframework.cloud.stream.binder.pulsar.PulsarMessageChannelBinder", "pulsar_key" - ); + "org.springframework.cloud.stream.binder.pulsar.PulsarMessageChannelBinder", "pulsar_key"); protected String getKeyHeaderName(String channelName, BindingServiceProperties bindingServiceProperties, BinderFactory binderFactory) { String binderConfigurationName = bindingServiceProperties.getBinder(channelName); var binder = binderFactory.getBinder(binderConfigurationName, MessageChannel.class); - if(binder == null) { + if (binder == null) { return null; } return messageKeyHeaders.get(binder.getClass().getName()); } protected String getTarget(Object event, RoutingTarget routingTarget) { - if(event instanceof Message message) { + if (event instanceof Message message) { var target = message.getHeaders().get(SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, String.class); - return target != null? target : routingTarget.getTarget(); + return target != null ? target : routingTarget.getTarget(); } return routingTarget.getTarget(); } diff --git a/src/main/java/io/zenwave360/modulith/events/scs/config/EnableSpringCloudStreamEventExternalization.java b/src/main/java/io/zenwave360/modulith/events/scs/config/EnableSpringCloudStreamEventExternalization.java index 94e8f81..1211161 100644 --- a/src/main/java/io/zenwave360/modulith/events/scs/config/EnableSpringCloudStreamEventExternalization.java +++ b/src/main/java/io/zenwave360/modulith/events/scs/config/EnableSpringCloudStreamEventExternalization.java @@ -9,8 +9,9 @@ import java.lang.annotation.Target; @Configuration -@Import({ SpringCloudStreamEventExternalizerConfiguration.class, EventSerializerConfiguration.class}) +@Import({ SpringCloudStreamEventExternalizerConfiguration.class, EventSerializerConfiguration.class }) @Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface EnableSpringCloudStreamEventExternalization { + } diff --git a/src/main/java/io/zenwave360/modulith/events/scs/config/EventSerializerConfiguration.java b/src/main/java/io/zenwave360/modulith/events/scs/config/EventSerializerConfiguration.java index 9d38c49..504d583 100644 --- a/src/main/java/io/zenwave360/modulith/events/scs/config/EventSerializerConfiguration.java +++ b/src/main/java/io/zenwave360/modulith/events/scs/config/EventSerializerConfiguration.java @@ -16,8 +16,7 @@ @AutoConfiguration @AutoConfigureAfter(EventExternalizationAutoConfiguration.class) -@ConditionalOnProperty(name = "spring.modulith.events.externalization.enabled", - havingValue = "true", +@ConditionalOnProperty(name = "spring.modulith.events.externalization.enabled", havingValue = "true", matchIfMissing = true) public class EventSerializerConfiguration { @@ -34,4 +33,5 @@ public EventSerializer avroEventSerializer(ObjectMapper mapper) { public EventSerializer messageEventSerializer(ObjectMapper mapper) { return new MessageEventSerializer(mapper); } + } diff --git a/src/main/java/io/zenwave360/modulith/events/scs/config/SpringCloudStreamEventExternalizerConfiguration.java b/src/main/java/io/zenwave360/modulith/events/scs/config/SpringCloudStreamEventExternalizerConfiguration.java index fcd2174..6261045 100644 --- a/src/main/java/io/zenwave360/modulith/events/scs/config/SpringCloudStreamEventExternalizerConfiguration.java +++ b/src/main/java/io/zenwave360/modulith/events/scs/config/SpringCloudStreamEventExternalizerConfiguration.java @@ -36,7 +36,8 @@ import org.springframework.modulith.events.support.DelegatingEventExternalizer; /** - * Auto-configuration to set up a {@link DelegatingEventExternalizer} to externalize events to Spring Cloud Stream. + * Auto-configuration to set up a {@link DelegatingEventExternalizer} to externalize + * events to Spring Cloud Stream. * * @author ivangsa * @since 1.3 @@ -45,39 +46,39 @@ @AutoConfiguration @AutoConfigureAfter(EventExternalizationAutoConfiguration.class) @ConditionalOnClass(StreamBridge.class) -@ConditionalOnProperty(name = "spring.modulith.events.externalization.enabled", - havingValue = "true", - matchIfMissing = true) +@ConditionalOnProperty(name = "spring.modulith.events.externalization.enabled", havingValue = "true", + matchIfMissing = true) public class SpringCloudStreamEventExternalizerConfiguration { - private static final Logger log = LoggerFactory.getLogger(SpringCloudStreamEventExternalizerConfiguration.class); + private static final Logger log = LoggerFactory.getLogger(SpringCloudStreamEventExternalizerConfiguration.class); - @Bean - EventExternalizationConfiguration eventExternalizationConfiguration() { - return EventExternalizationConfiguration.externalizing() - .select(event -> event instanceof Message && getTarget(event) != null) - .routeAll(event -> RoutingTarget.forTarget(getTarget(event)).withoutKey()) - .build(); - } + @Bean + EventExternalizationConfiguration eventExternalizationConfiguration() { + return EventExternalizationConfiguration.externalizing() + .select(event -> event instanceof Message && getTarget(event) != null) + .routeAll(event -> RoutingTarget.forTarget(getTarget(event)).withoutKey()) + .build(); + } - private String getTarget(Object event) { - if(event instanceof Message message) { - return message.getHeaders().get(SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, String.class); - } - return null; - } + private String getTarget(Object event) { + if (event instanceof Message message) { + return message.getHeaders() + .get(SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, String.class); + } + return null; + } - @Bean - DelegatingEventExternalizer springCloudStreamMessageExternalizer( - EventExternalizationConfiguration configuration, - StreamBridge streamBridge, BeanFactory factory, - BindingServiceProperties bindingServiceProperties, - BinderFactory binderFactory) { - log.debug("Registering domain event externalization to Spring Cloud Stream…"); + @Bean + DelegatingEventExternalizer springCloudStreamMessageExternalizer(EventExternalizationConfiguration configuration, + StreamBridge streamBridge, BeanFactory factory, BindingServiceProperties bindingServiceProperties, + BinderFactory binderFactory) { + log.debug("Registering domain event externalization to Spring Cloud Stream…"); - var context = new StandardEvaluationContext(); - context.setBeanResolver(new BeanFactoryResolver(factory)); + var context = new StandardEvaluationContext(); + context.setBeanResolver(new BeanFactoryResolver(factory)); + + return new DelegatingEventExternalizer(configuration, new SpringCloudStreamEventExternalizer(configuration, + context, streamBridge, bindingServiceProperties, binderFactory)); + } - return new DelegatingEventExternalizer(configuration, new SpringCloudStreamEventExternalizer(configuration, context, streamBridge, bindingServiceProperties, binderFactory)); - } } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/AvroEventSerializerTest.java b/src/test/java/io/zenwave360/modulith/events/scs/AvroEventSerializerTest.java index 3d7b62f..1a95f36 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/AvroEventSerializerTest.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/AvroEventSerializerTest.java @@ -12,7 +12,6 @@ public class AvroEventSerializerTest { - private EventSerializer eventSerializer; @BeforeEach @@ -24,16 +23,14 @@ public void setUp() { public void testSerializeMessage() { var customerEvent = new CustomerEvent(); customerEvent.setName("John Doe"); - Message message = MessageBuilder - .withPayload(customerEvent) - .setHeader("headerKey", "headerValue") - .build(); + Message message = MessageBuilder.withPayload(customerEvent).setHeader("headerKey", "headerValue").build(); Object serialized = eventSerializer.serialize(message); Assertions.assertTrue(serialized instanceof String); Assertions.assertTrue(serialized.toString().contains("\"name\":\"John Doe\",")); - Assertions.assertTrue(serialized.toString().contains("\"_class\":\"io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent\"")); + Assertions.assertTrue(serialized.toString() + .contains("\"_class\":\"io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent\"")); } @Test @@ -74,10 +71,7 @@ public void testDeserializeMessage() throws JsonProcessingException, ClassNotFou public void testSerializeDeserializeMessage() throws JsonProcessingException, ClassNotFoundException { var customerEvent = new CustomerEvent(); customerEvent.setName("John Doe"); - Message message = MessageBuilder - .withPayload(customerEvent) - .setHeader("headerKey", "headerValue") - .build(); + Message message = MessageBuilder.withPayload(customerEvent).setHeader("headerKey", "headerValue").build(); Object serialized = eventSerializer.serialize(message); Message deserialized = eventSerializer.deserialize(serialized, Message.class); @@ -96,4 +90,5 @@ public void testSerializeDeserializeObject() throws JsonProcessingException, Cla Assertions.assertEquals(CustomerEvent.class, deserialized.getClass()); Assertions.assertEquals(customerEvent.getName(), ((CustomerEvent) deserialized).getName()); } + } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/MessageEventSerializerTest.java b/src/test/java/io/zenwave360/modulith/events/scs/MessageEventSerializerTest.java index c6b9f04..82ecdae 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/MessageEventSerializerTest.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/MessageEventSerializerTest.java @@ -13,6 +13,7 @@ public class MessageEventSerializerTest { private ObjectMapper objectMapper; + private EventSerializer eventSerializer; @BeforeEach @@ -24,16 +25,14 @@ public void setUp() { @Test public void testSerializeMessage() { var customerEvent = new CustomerEvent().withName("John Doe"); - Message message = MessageBuilder - .withPayload(customerEvent) - .setHeader("headerKey", "headerValue") - .build(); + Message message = MessageBuilder.withPayload(customerEvent).setHeader("headerKey", "headerValue").build(); Object serialized = eventSerializer.serialize(message); Assertions.assertTrue(serialized instanceof String); Assertions.assertTrue(serialized.toString().contains("\"payload\":{\"name\":\"John Doe\",")); - Assertions.assertTrue(serialized.toString().contains("\"_class\":\"io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent\"")); + Assertions.assertTrue(serialized.toString() + .contains("\"_class\":\"io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent\"")); } @Test @@ -73,10 +72,7 @@ public void testDeserializeMessage() throws JsonProcessingException, ClassNotFou @Test public void testSerializeDeserializeMessage() throws JsonProcessingException, ClassNotFoundException { var customerEvent = new CustomerEvent().withName("John Doe"); - Message message = MessageBuilder - .withPayload(customerEvent) - .setHeader("headerKey", "headerValue") - .build(); + Message message = MessageBuilder.withPayload(customerEvent).setHeader("headerKey", "headerValue").build(); Object serialized = eventSerializer.serialize(message); Message deserialized = eventSerializer.deserialize(serialized, Message.class); @@ -93,4 +89,5 @@ public void testSerializeDeserializeObject() throws JsonProcessingException, Cla Assertions.assertEquals(CustomerEvent.class, deserialized.getClass()); } + } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/SCSAvroEventExternalizerTest.java b/src/test/java/io/zenwave360/modulith/events/scs/SCSAvroEventExternalizerTest.java index ac3034e..7362cc5 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/SCSAvroEventExternalizerTest.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/SCSAvroEventExternalizerTest.java @@ -28,4 +28,5 @@ void testExternalizeAvroEvent() throws InterruptedException { Thread.sleep(5000); // TODO: Assert that the event was externalized } + } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/SCSJsonEventExternalizerTest.java b/src/test/java/io/zenwave360/modulith/events/scs/SCSJsonEventExternalizerTest.java index 04dc70b..8dc63e2 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/SCSJsonEventExternalizerTest.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/SCSJsonEventExternalizerTest.java @@ -21,11 +21,11 @@ public class SCSJsonEventExternalizerTest { @Test void testExternalizeJsonEvent() throws InterruptedException { - var event = new io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent() - .withName("John Doe"); + var event = new io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent().withName("John Doe"); customerEventsProducer.onCustomerEventJson(event); // Wait for the event to be externalized Thread.sleep(5000); // TODO: Assert that the event was externalized } + } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/TestsConfiguration.java b/src/test/java/io/zenwave360/modulith/events/scs/TestsConfiguration.java index bd42062..2f7d8cf 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/TestsConfiguration.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/TestsConfiguration.java @@ -46,22 +46,24 @@ public CustomerEventsProducer(ApplicationEventPublisher applicationEventPublishe @Transactional(propagation = Propagation.REQUIRES_NEW) public void onCustomerEventJson(io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent event) { - Message message = MessageBuilder.withPayload(event) - .setHeader( - SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, - "customers-json-out-0") // <- target binding name - .build(); + Message message = MessageBuilder + .withPayload(event) + .setHeader(SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, + "customers-json-out-0") // <- target binding name + .build(); applicationEventPublisher.publishEvent(message); } @Transactional(propagation = Propagation.REQUIRES_NEW) public void onCustomerEventAvro(io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent event) { - Message message = MessageBuilder.withPayload(event) - .setHeader( - SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, - "customers-avro-out-0") // <- target binding name - .build(); + Message message = MessageBuilder + .withPayload(event) + .setHeader(SpringCloudStreamEventExternalizer.SPRING_CLOUD_STREAM_SENDTO_DESTINATION_HEADER, + "customers-avro-out-0") // <- target binding name + .build(); applicationEventPublisher.publishEvent(message); } + } + } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/Address.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/Address.java index 9e33a21..044b7a8 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/Address.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/Address.java @@ -12,387 +12,401 @@ import org.apache.avro.util.Utf8; @org.apache.avro.specific.AvroGenerated -public class Address extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = 7121751969643202111L; - - - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Address\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]}"); - public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } - - private static final SpecificData MODEL$ = new SpecificData(); - - private static final BinaryMessageEncoder
ENCODER = - new BinaryMessageEncoder<>(MODEL$, SCHEMA$); - - private static final BinaryMessageDecoder
DECODER = - new BinaryMessageDecoder<>(MODEL$, SCHEMA$); - - /** - * Return the BinaryMessageEncoder instance used by this class. - * @return the message encoder used by this class - */ - public static BinaryMessageEncoder
getEncoder() { - return ENCODER; - } - - /** - * Return the BinaryMessageDecoder instance used by this class. - * @return the message decoder used by this class - */ - public static BinaryMessageDecoder
getDecoder() { - return DECODER; - } - - /** - * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. - * @param resolver a {@link SchemaStore} used to find schemas by fingerprint - * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore - */ - public static BinaryMessageDecoder
createDecoder(SchemaStore resolver) { - return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver); - } - - /** - * Serializes this Address to a ByteBuffer. - * @return a buffer holding the serialized data for this instance - * @throws java.io.IOException if this instance could not be serialized - */ - public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { - return ENCODER.encode(this); - } - - /** - * Deserializes a Address from a ByteBuffer. - * @param b a byte buffer holding serialized data for an instance of this class - * @return a Address instance decoded from the given buffer - * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class - */ - public static Address fromByteBuffer( - java.nio.ByteBuffer b) throws java.io.IOException { - return DECODER.decode(b); - } - - private CharSequence street; - private CharSequence city; - - /** - * Default constructor. Note that this does not initialize fields - * to their default values from the schema. If that is desired then - * one should use newBuilder(). - */ - public Address() {} - - /** - * All-args constructor. - * @param street The new value for street - * @param city The new value for city - */ - public Address(CharSequence street, CharSequence city) { - this.street = street; - this.city = city; - } - - @Override - public SpecificData getSpecificData() { return MODEL$; } - - @Override - public org.apache.avro.Schema getSchema() { return SCHEMA$; } - - // Used by DatumWriter. Applications should not call. - @Override - public Object get(int field$) { - switch (field$) { - case 0: return street; - case 1: return city; - default: throw new IndexOutOfBoundsException("Invalid index: " + field$); - } - } - - // Used by DatumReader. Applications should not call. - @Override - @SuppressWarnings(value="unchecked") - public void put(int field$, Object value$) { - switch (field$) { - case 0: street = (CharSequence)value$; break; - case 1: city = (CharSequence)value$; break; - default: throw new IndexOutOfBoundsException("Invalid index: " + field$); - } - } - - /** - * Gets the value of the 'street' field. - * @return The value of the 'street' field. - */ - public CharSequence getStreet() { - return street; - } - - - /** - * Sets the value of the 'street' field. - * @param value the value to set. - */ - public void setStreet(CharSequence value) { - this.street = value; - } - - /** - * Gets the value of the 'city' field. - * @return The value of the 'city' field. - */ - public CharSequence getCity() { - return city; - } - - - /** - * Sets the value of the 'city' field. - * @param value the value to set. - */ - public void setCity(CharSequence value) { - this.city = value; - } - - /** - * Creates a new Address RecordBuilder. - * @return A new Address RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder newBuilder() { - return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(); - } - - /** - * Creates a new Address RecordBuilder by copying an existing Builder. - * @param other The existing builder to copy. - * @return A new Address RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder newBuilder(io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder other) { - if (other == null) { - return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(); - } else { - return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(other); - } - } - - /** - * Creates a new Address RecordBuilder by copying an existing Address instance. - * @param other The existing instance to copy. - * @return A new Address RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder newBuilder(io.zenwave360.modulith.events.scs.dtos.avro.Address other) { - if (other == null) { - return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(); - } else { - return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(other); +public class Address extends org.apache.avro.specific.SpecificRecordBase + implements org.apache.avro.specific.SpecificRecord { + + private static final long serialVersionUID = 7121751969643202111L; + + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( + "{\"type\":\"record\",\"name\":\"Address\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]}"); + + public static org.apache.avro.Schema getClassSchema() { + return SCHEMA$; } - } - /** - * RecordBuilder for Address instances. - */ - @org.apache.avro.specific.AvroGenerated - public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase
- implements org.apache.avro.data.RecordBuilder
{ + private static final SpecificData MODEL$ = new SpecificData(); - private CharSequence street; - private CharSequence city; + private static final BinaryMessageEncoder
ENCODER = new BinaryMessageEncoder<>(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder
DECODER = new BinaryMessageDecoder<>(MODEL$, SCHEMA$); - /** Creates a new Builder */ - private Builder() { - super(SCHEMA$, MODEL$); + /** + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class + */ + public static BinaryMessageEncoder
getEncoder() { + return ENCODER; } /** - * Creates a Builder by copying an existing Builder. - * @param other The existing Builder to copy. + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class */ - private Builder(io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder other) { - super(other); - if (isValidValue(fields()[0], other.street)) { - this.street = data().deepCopy(fields()[0].schema(), other.street); - fieldSetFlags()[0] = other.fieldSetFlags()[0]; - } - if (isValidValue(fields()[1], other.city)) { - this.city = data().deepCopy(fields()[1].schema(), other.city); - fieldSetFlags()[1] = other.fieldSetFlags()[1]; - } + public static BinaryMessageDecoder
getDecoder() { + return DECODER; } /** - * Creates a Builder by copying an existing Address instance - * @param other The existing instance to copy. + * Create a new BinaryMessageDecoder instance for this class that uses the specified + * {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given + * SchemaStore */ - private Builder(io.zenwave360.modulith.events.scs.dtos.avro.Address other) { - super(SCHEMA$, MODEL$); - if (isValidValue(fields()[0], other.street)) { - this.street = data().deepCopy(fields()[0].schema(), other.street); - fieldSetFlags()[0] = true; - } - if (isValidValue(fields()[1], other.city)) { - this.city = data().deepCopy(fields()[1].schema(), other.city); - fieldSetFlags()[1] = true; - } + public static BinaryMessageDecoder
createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver); } /** - * Gets the value of the 'street' field. - * @return The value. - */ - public CharSequence getStreet() { - return street; + * Serializes this Address to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); } + /** + * Deserializes a Address from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a Address instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an + * instance of this class + */ + public static Address fromByteBuffer(java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); + } + + private CharSequence street; + + private CharSequence city; /** - * Sets the value of the 'street' field. - * @param value The value of 'street'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder setStreet(CharSequence value) { - validate(fields()[0], value); - this.street = value; - fieldSetFlags()[0] = true; - return this; + * Default constructor. Note that this does not initialize fields to their default + * values from the schema. If that is desired then one should use + * newBuilder(). + */ + public Address() { } /** - * Checks whether the 'street' field has been set. - * @return True if the 'street' field has been set, false otherwise. - */ - public boolean hasStreet() { - return fieldSetFlags()[0]; + * All-args constructor. + * @param street The new value for street + * @param city The new value for city + */ + public Address(CharSequence street, CharSequence city) { + this.street = street; + this.city = city; } + @Override + public SpecificData getSpecificData() { + return MODEL$; + } - /** - * Clears the value of the 'street' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder clearStreet() { - street = null; - fieldSetFlags()[0] = false; - return this; + @Override + public org.apache.avro.Schema getSchema() { + return SCHEMA$; + } + + // Used by DatumWriter. Applications should not call. + @Override + public Object get(int field$) { + switch (field$) { + case 0: + return street; + case 1: + return city; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } + + // Used by DatumReader. Applications should not call. + @Override + @SuppressWarnings(value = "unchecked") + public void put(int field$, Object value$) { + switch (field$) { + case 0: + street = (CharSequence) value$; + break; + case 1: + city = (CharSequence) value$; + break; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } } /** - * Gets the value of the 'city' field. - * @return The value. - */ - public CharSequence getCity() { - return city; + * Gets the value of the 'street' field. + * @return The value of the 'street' field. + */ + public CharSequence getStreet() { + return street; } + /** + * Sets the value of the 'street' field. + * @param value the value to set. + */ + public void setStreet(CharSequence value) { + this.street = value; + } /** - * Sets the value of the 'city' field. - * @param value The value of 'city'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder setCity(CharSequence value) { - validate(fields()[1], value); - this.city = value; - fieldSetFlags()[1] = true; - return this; + * Gets the value of the 'city' field. + * @return The value of the 'city' field. + */ + public CharSequence getCity() { + return city; } /** - * Checks whether the 'city' field has been set. - * @return True if the 'city' field has been set, false otherwise. - */ - public boolean hasCity() { - return fieldSetFlags()[1]; + * Sets the value of the 'city' field. + * @param value the value to set. + */ + public void setCity(CharSequence value) { + this.city = value; } + /** + * Creates a new Address RecordBuilder. + * @return A new Address RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder newBuilder() { + return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(); + } /** - * Clears the value of the 'city' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder clearCity() { - city = null; - fieldSetFlags()[1] = false; - return this; + * Creates a new Address RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new Address RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder newBuilder( + io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder other) { + if (other == null) { + return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(); + } + else { + return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(other); + } } - @Override - @SuppressWarnings("unchecked") - public Address build() { - try { - Address record = new Address(); - record.street = fieldSetFlags()[0] ? this.street : (CharSequence) defaultValue(fields()[0]); - record.city = fieldSetFlags()[1] ? this.city : (CharSequence) defaultValue(fields()[1]); - return record; - } catch (org.apache.avro.AvroMissingFieldException e) { - throw e; - } catch (Exception e) { - throw new org.apache.avro.AvroRuntimeException(e); - } + /** + * Creates a new Address RecordBuilder by copying an existing Address instance. + * @param other The existing instance to copy. + * @return A new Address RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder newBuilder( + io.zenwave360.modulith.events.scs.dtos.avro.Address other) { + if (other == null) { + return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(); + } + else { + return new io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder(other); + } } - } - @SuppressWarnings("unchecked") - private static final org.apache.avro.io.DatumWriter
- WRITER$ = (org.apache.avro.io.DatumWriter
)MODEL$.createDatumWriter(SCHEMA$); + /** + * RecordBuilder for Address instances. + */ + @org.apache.avro.specific.AvroGenerated + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase
+ implements org.apache.avro.data.RecordBuilder
{ - @Override public void writeExternal(java.io.ObjectOutput out) - throws java.io.IOException { - WRITER$.write(this, SpecificData.getEncoder(out)); - } + private CharSequence street; - @SuppressWarnings("unchecked") - private static final org.apache.avro.io.DatumReader
- READER$ = (org.apache.avro.io.DatumReader
)MODEL$.createDatumReader(SCHEMA$); + private CharSequence city; - @Override public void readExternal(java.io.ObjectInput in) - throws java.io.IOException { - READER$.read(this, SpecificData.getDecoder(in)); - } + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$, MODEL$); + } - @Override protected boolean hasCustomCoders() { return true; } + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder other) { + super(other); + if (isValidValue(fields()[0], other.street)) { + this.street = data().deepCopy(fields()[0].schema(), other.street); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.city)) { + this.city = data().deepCopy(fields()[1].schema(), other.city); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + } - @Override public void customEncode(org.apache.avro.io.Encoder out) - throws java.io.IOException - { - out.writeString(this.street); + /** + * Creates a Builder by copying an existing Address instance + * @param other The existing instance to copy. + */ + private Builder(io.zenwave360.modulith.events.scs.dtos.avro.Address other) { + super(SCHEMA$, MODEL$); + if (isValidValue(fields()[0], other.street)) { + this.street = data().deepCopy(fields()[0].schema(), other.street); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.city)) { + this.city = data().deepCopy(fields()[1].schema(), other.city); + fieldSetFlags()[1] = true; + } + } - out.writeString(this.city); + /** + * Gets the value of the 'street' field. + * @return The value. + */ + public CharSequence getStreet() { + return street; + } - } + /** + * Sets the value of the 'street' field. + * @param value The value of 'street'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder setStreet(CharSequence value) { + validate(fields()[0], value); + this.street = value; + fieldSetFlags()[0] = true; + return this; + } - @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) - throws java.io.IOException - { - org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); - if (fieldOrder == null) { - this.street = in.readString(this.street instanceof Utf8 ? (Utf8)this.street : null); + /** + * Checks whether the 'street' field has been set. + * @return True if the 'street' field has been set, false otherwise. + */ + public boolean hasStreet() { + return fieldSetFlags()[0]; + } - this.city = in.readString(this.city instanceof Utf8 ? (Utf8)this.city : null); + /** + * Clears the value of the 'street' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder clearStreet() { + street = null; + fieldSetFlags()[0] = false; + return this; + } - } else { - for (int i = 0; i < 2; i++) { - switch (fieldOrder[i].pos()) { - case 0: - this.street = in.readString(this.street instanceof Utf8 ? (Utf8)this.street : null); - break; + /** + * Gets the value of the 'city' field. + * @return The value. + */ + public CharSequence getCity() { + return city; + } - case 1: - this.city = in.readString(this.city instanceof Utf8 ? (Utf8)this.city : null); - break; + /** + * Sets the value of the 'city' field. + * @param value The value of 'city'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder setCity(CharSequence value) { + validate(fields()[1], value); + this.city = value; + fieldSetFlags()[1] = true; + return this; + } - default: - throw new java.io.IOException("Corrupt ResolvingDecoder."); + /** + * Checks whether the 'city' field has been set. + * @return True if the 'city' field has been set, false otherwise. + */ + public boolean hasCity() { + return fieldSetFlags()[1]; } - } + + /** + * Clears the value of the 'city' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.Address.Builder clearCity() { + city = null; + fieldSetFlags()[1] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public Address build() { + try { + Address record = new Address(); + record.street = fieldSetFlags()[0] ? this.street : (CharSequence) defaultValue(fields()[0]); + record.city = fieldSetFlags()[1] ? this.city : (CharSequence) defaultValue(fields()[1]); + return record; + } + catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } + catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } - } -} + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter
WRITER$ = (org.apache.avro.io.DatumWriter
) MODEL$ + .createDatumWriter(SCHEMA$); + + @Override + public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader
READER$ = (org.apache.avro.io.DatumReader
) MODEL$ + .createDatumReader(SCHEMA$); + @Override + public void readExternal(java.io.ObjectInput in) throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + @Override + protected boolean hasCustomCoders() { + return true; + } + @Override + public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException { + out.writeString(this.street); + out.writeString(this.city); + } + @Override + public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.street = in.readString(this.street instanceof Utf8 ? (Utf8) this.street : null); + this.city = in.readString(this.city instanceof Utf8 ? (Utf8) this.city : null); + } + else { + for (int i = 0; i < 2; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.street = in.readString(this.street instanceof Utf8 ? (Utf8) this.street : null); + break; + + case 1: + this.city = in.readString(this.city instanceof Utf8 ? (Utf8) this.city : null); + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/CustomerEvent.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/CustomerEvent.java index 07afa4e..bc28999 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/CustomerEvent.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/CustomerEvent.java @@ -12,832 +12,885 @@ import org.apache.avro.util.Utf8; @org.apache.avro.specific.AvroGenerated -public class CustomerEvent extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = -8546638608361810155L; - - - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"CustomerEvent\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Customer name\"},{\"name\":\"email\",\"type\":\"string\",\"doc\":\"\"},{\"name\":\"addresses\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Address\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]},\"java-class\":\"java.util.List\"}},{\"name\":\"id\",\"type\":[\"null\",\"long\"]},{\"name\":\"version\",\"type\":[\"null\",\"int\"]},{\"name\":\"paymentMethods\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"PaymentMethod\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"type\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentMethodType\",\"symbols\":[\"VISA\",\"MASTERCARD\"]}},{\"name\":\"cardNumber\",\"type\":\"string\"}]},\"java-class\":\"java.util.List\"}}]}"); - public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } - - private static final SpecificData MODEL$ = new SpecificData(); - - private static final BinaryMessageEncoder ENCODER = - new BinaryMessageEncoder<>(MODEL$, SCHEMA$); - - private static final BinaryMessageDecoder DECODER = - new BinaryMessageDecoder<>(MODEL$, SCHEMA$); - - /** - * Return the BinaryMessageEncoder instance used by this class. - * @return the message encoder used by this class - */ - public static BinaryMessageEncoder getEncoder() { - return ENCODER; - } - - /** - * Return the BinaryMessageDecoder instance used by this class. - * @return the message decoder used by this class - */ - public static BinaryMessageDecoder getDecoder() { - return DECODER; - } - - /** - * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. - * @param resolver a {@link SchemaStore} used to find schemas by fingerprint - * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore - */ - public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { - return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver); - } - - /** - * Serializes this CustomerEvent to a ByteBuffer. - * @return a buffer holding the serialized data for this instance - * @throws java.io.IOException if this instance could not be serialized - */ - public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { - return ENCODER.encode(this); - } - - /** - * Deserializes a CustomerEvent from a ByteBuffer. - * @param b a byte buffer holding serialized data for an instance of this class - * @return a CustomerEvent instance decoded from the given buffer - * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class - */ - public static CustomerEvent fromByteBuffer( - java.nio.ByteBuffer b) throws java.io.IOException { - return DECODER.decode(b); - } - - /** Customer name */ - private CharSequence name; - private CharSequence email; - private java.util.List addresses; - private Long id; - private Integer version; - private java.util.List paymentMethods; - - /** - * Default constructor. Note that this does not initialize fields - * to their default values from the schema. If that is desired then - * one should use newBuilder(). - */ - public CustomerEvent() {} - - /** - * All-args constructor. - * @param name Customer name - * @param email The new value for email - * @param addresses The new value for addresses - * @param id The new value for id - * @param version The new value for version - * @param paymentMethods The new value for paymentMethods - */ - public CustomerEvent(CharSequence name, CharSequence email, java.util.List addresses, Long id, Integer version, java.util.List paymentMethods) { - this.name = name; - this.email = email; - this.addresses = addresses; - this.id = id; - this.version = version; - this.paymentMethods = paymentMethods; - } - - @Override - public SpecificData getSpecificData() { return MODEL$; } - - @Override - public org.apache.avro.Schema getSchema() { return SCHEMA$; } - - // Used by DatumWriter. Applications should not call. - @Override - public Object get(int field$) { - switch (field$) { - case 0: return name; - case 1: return email; - case 2: return addresses; - case 3: return id; - case 4: return version; - case 5: return paymentMethods; - default: throw new IndexOutOfBoundsException("Invalid index: " + field$); - } - } - - // Used by DatumReader. Applications should not call. - @Override - @SuppressWarnings(value="unchecked") - public void put(int field$, Object value$) { - switch (field$) { - case 0: name = (CharSequence)value$; break; - case 1: email = (CharSequence)value$; break; - case 2: addresses = (java.util.List)value$; break; - case 3: id = (Long)value$; break; - case 4: version = (Integer)value$; break; - case 5: paymentMethods = (java.util.List)value$; break; - default: throw new IndexOutOfBoundsException("Invalid index: " + field$); - } - } - - /** - * Gets the value of the 'name' field. - * @return Customer name - */ - public CharSequence getName() { - return name; - } - - - /** - * Sets the value of the 'name' field. - * Customer name - * @param value the value to set. - */ - public void setName(CharSequence value) { - this.name = value; - } - - /** - * Gets the value of the 'email' field. - * @return The value of the 'email' field. - */ - public CharSequence getEmail() { - return email; - } - - - /** - * Sets the value of the 'email' field. - * @param value the value to set. - */ - public void setEmail(CharSequence value) { - this.email = value; - } - - /** - * Gets the value of the 'addresses' field. - * @return The value of the 'addresses' field. - */ - public java.util.List getAddresses() { - return addresses; - } - - - /** - * Sets the value of the 'addresses' field. - * @param value the value to set. - */ - public void setAddresses(java.util.List value) { - this.addresses = value; - } - - /** - * Gets the value of the 'id' field. - * @return The value of the 'id' field. - */ - public Long getId() { - return id; - } - - - /** - * Sets the value of the 'id' field. - * @param value the value to set. - */ - public void setId(Long value) { - this.id = value; - } - - /** - * Gets the value of the 'version' field. - * @return The value of the 'version' field. - */ - public Integer getVersion() { - return version; - } - - - /** - * Sets the value of the 'version' field. - * @param value the value to set. - */ - public void setVersion(Integer value) { - this.version = value; - } - - /** - * Gets the value of the 'paymentMethods' field. - * @return The value of the 'paymentMethods' field. - */ - public java.util.List getPaymentMethods() { - return paymentMethods; - } - - - /** - * Sets the value of the 'paymentMethods' field. - * @param value the value to set. - */ - public void setPaymentMethods(java.util.List value) { - this.paymentMethods = value; - } - - /** - * Creates a new CustomerEvent RecordBuilder. - * @return A new CustomerEvent RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder newBuilder() { - return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(); - } - - /** - * Creates a new CustomerEvent RecordBuilder by copying an existing Builder. - * @param other The existing builder to copy. - * @return A new CustomerEvent RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder newBuilder(io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder other) { - if (other == null) { - return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(); - } else { - return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(other); - } - } - - /** - * Creates a new CustomerEvent RecordBuilder by copying an existing CustomerEvent instance. - * @param other The existing instance to copy. - * @return A new CustomerEvent RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder newBuilder(io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent other) { - if (other == null) { - return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(); - } else { - return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(other); - } - } - - /** - * RecordBuilder for CustomerEvent instances. - */ - @org.apache.avro.specific.AvroGenerated - public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase - implements org.apache.avro.data.RecordBuilder { +public class CustomerEvent extends org.apache.avro.specific.SpecificRecordBase + implements org.apache.avro.specific.SpecificRecord { - /** Customer name */ - private CharSequence name; - private CharSequence email; - private java.util.List addresses; - private Long id; - private Integer version; - private java.util.List paymentMethods; + private static final long serialVersionUID = -8546638608361810155L; + + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( + "{\"type\":\"record\",\"name\":\"CustomerEvent\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"fields\":[{\"name\":\"name\",\"type\":\"string\",\"doc\":\"Customer name\"},{\"name\":\"email\",\"type\":\"string\",\"doc\":\"\"},{\"name\":\"addresses\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Address\",\"fields\":[{\"name\":\"street\",\"type\":\"string\"},{\"name\":\"city\",\"type\":\"string\"}]},\"java-class\":\"java.util.List\"}},{\"name\":\"id\",\"type\":[\"null\",\"long\"]},{\"name\":\"version\",\"type\":[\"null\",\"int\"]},{\"name\":\"paymentMethods\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"PaymentMethod\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"type\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentMethodType\",\"symbols\":[\"VISA\",\"MASTERCARD\"]}},{\"name\":\"cardNumber\",\"type\":\"string\"}]},\"java-class\":\"java.util.List\"}}]}"); - /** Creates a new Builder */ - private Builder() { - super(SCHEMA$, MODEL$); + public static org.apache.avro.Schema getClassSchema() { + return SCHEMA$; } + private static final SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = new BinaryMessageEncoder<>(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = new BinaryMessageDecoder<>(MODEL$, SCHEMA$); + /** - * Creates a Builder by copying an existing Builder. - * @param other The existing Builder to copy. + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class */ - private Builder(io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder other) { - super(other); - if (isValidValue(fields()[0], other.name)) { - this.name = data().deepCopy(fields()[0].schema(), other.name); - fieldSetFlags()[0] = other.fieldSetFlags()[0]; - } - if (isValidValue(fields()[1], other.email)) { - this.email = data().deepCopy(fields()[1].schema(), other.email); - fieldSetFlags()[1] = other.fieldSetFlags()[1]; - } - if (isValidValue(fields()[2], other.addresses)) { - this.addresses = data().deepCopy(fields()[2].schema(), other.addresses); - fieldSetFlags()[2] = other.fieldSetFlags()[2]; - } - if (isValidValue(fields()[3], other.id)) { - this.id = data().deepCopy(fields()[3].schema(), other.id); - fieldSetFlags()[3] = other.fieldSetFlags()[3]; - } - if (isValidValue(fields()[4], other.version)) { - this.version = data().deepCopy(fields()[4].schema(), other.version); - fieldSetFlags()[4] = other.fieldSetFlags()[4]; - } - if (isValidValue(fields()[5], other.paymentMethods)) { - this.paymentMethods = data().deepCopy(fields()[5].schema(), other.paymentMethods); - fieldSetFlags()[5] = other.fieldSetFlags()[5]; - } + public static BinaryMessageEncoder getEncoder() { + return ENCODER; } /** - * Creates a Builder by copying an existing CustomerEvent instance - * @param other The existing instance to copy. + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class */ - private Builder(io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent other) { - super(SCHEMA$, MODEL$); - if (isValidValue(fields()[0], other.name)) { - this.name = data().deepCopy(fields()[0].schema(), other.name); - fieldSetFlags()[0] = true; - } - if (isValidValue(fields()[1], other.email)) { - this.email = data().deepCopy(fields()[1].schema(), other.email); - fieldSetFlags()[1] = true; - } - if (isValidValue(fields()[2], other.addresses)) { - this.addresses = data().deepCopy(fields()[2].schema(), other.addresses); - fieldSetFlags()[2] = true; - } - if (isValidValue(fields()[3], other.id)) { - this.id = data().deepCopy(fields()[3].schema(), other.id); - fieldSetFlags()[3] = true; - } - if (isValidValue(fields()[4], other.version)) { - this.version = data().deepCopy(fields()[4].schema(), other.version); - fieldSetFlags()[4] = true; - } - if (isValidValue(fields()[5], other.paymentMethods)) { - this.paymentMethods = data().deepCopy(fields()[5].schema(), other.paymentMethods); - fieldSetFlags()[5] = true; - } + public static BinaryMessageDecoder getDecoder() { + return DECODER; } /** - * Gets the value of the 'name' field. - * Customer name - * @return The value. - */ - public CharSequence getName() { - return name; + * Create a new BinaryMessageDecoder instance for this class that uses the specified + * {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given + * SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver); } - /** - * Sets the value of the 'name' field. - * Customer name - * @param value The value of 'name'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setName(CharSequence value) { - validate(fields()[0], value); - this.name = value; - fieldSetFlags()[0] = true; - return this; + * Serializes this CustomerEvent to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); } /** - * Checks whether the 'name' field has been set. - * Customer name - * @return True if the 'name' field has been set, false otherwise. - */ - public boolean hasName() { - return fieldSetFlags()[0]; + * Deserializes a CustomerEvent from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a CustomerEvent instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an + * instance of this class + */ + public static CustomerEvent fromByteBuffer(java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); } + /** Customer name */ + private CharSequence name; - /** - * Clears the value of the 'name' field. - * Customer name - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearName() { - name = null; - fieldSetFlags()[0] = false; - return this; - } + private CharSequence email; - /** - * Gets the value of the 'email' field. - * @return The value. - */ - public CharSequence getEmail() { - return email; - } + private java.util.List addresses; + + private Long id; + + private Integer version; + private java.util.List paymentMethods; /** - * Sets the value of the 'email' field. - * @param value The value of 'email'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setEmail(CharSequence value) { - validate(fields()[1], value); - this.email = value; - fieldSetFlags()[1] = true; - return this; + * Default constructor. Note that this does not initialize fields to their default + * values from the schema. If that is desired then one should use + * newBuilder(). + */ + public CustomerEvent() { } /** - * Checks whether the 'email' field has been set. - * @return True if the 'email' field has been set, false otherwise. - */ - public boolean hasEmail() { - return fieldSetFlags()[1]; + * All-args constructor. + * @param name Customer name + * @param email The new value for email + * @param addresses The new value for addresses + * @param id The new value for id + * @param version The new value for version + * @param paymentMethods The new value for paymentMethods + */ + public CustomerEvent(CharSequence name, CharSequence email, + java.util.List addresses, Long id, Integer version, + java.util.List paymentMethods) { + this.name = name; + this.email = email; + this.addresses = addresses; + this.id = id; + this.version = version; + this.paymentMethods = paymentMethods; } + @Override + public SpecificData getSpecificData() { + return MODEL$; + } - /** - * Clears the value of the 'email' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearEmail() { - email = null; - fieldSetFlags()[1] = false; - return this; + @Override + public org.apache.avro.Schema getSchema() { + return SCHEMA$; } - /** - * Gets the value of the 'addresses' field. - * @return The value. - */ - public java.util.List getAddresses() { - return addresses; + // Used by DatumWriter. Applications should not call. + @Override + public Object get(int field$) { + switch (field$) { + case 0: + return name; + case 1: + return email; + case 2: + return addresses; + case 3: + return id; + case 4: + return version; + case 5: + return paymentMethods; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } } + // Used by DatumReader. Applications should not call. + @Override + @SuppressWarnings(value = "unchecked") + public void put(int field$, Object value$) { + switch (field$) { + case 0: + name = (CharSequence) value$; + break; + case 1: + email = (CharSequence) value$; + break; + case 2: + addresses = (java.util.List) value$; + break; + case 3: + id = (Long) value$; + break; + case 4: + version = (Integer) value$; + break; + case 5: + paymentMethods = (java.util.List) value$; + break; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } /** - * Sets the value of the 'addresses' field. - * @param value The value of 'addresses'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setAddresses(java.util.List value) { - validate(fields()[2], value); - this.addresses = value; - fieldSetFlags()[2] = true; - return this; + * Gets the value of the 'name' field. + * @return Customer name + */ + public CharSequence getName() { + return name; } /** - * Checks whether the 'addresses' field has been set. - * @return True if the 'addresses' field has been set, false otherwise. - */ - public boolean hasAddresses() { - return fieldSetFlags()[2]; + * Sets the value of the 'name' field. Customer name + * @param value the value to set. + */ + public void setName(CharSequence value) { + this.name = value; } - /** - * Clears the value of the 'addresses' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearAddresses() { - addresses = null; - fieldSetFlags()[2] = false; - return this; + * Gets the value of the 'email' field. + * @return The value of the 'email' field. + */ + public CharSequence getEmail() { + return email; } /** - * Gets the value of the 'id' field. - * @return The value. - */ - public Long getId() { - return id; + * Sets the value of the 'email' field. + * @param value the value to set. + */ + public void setEmail(CharSequence value) { + this.email = value; } - /** - * Sets the value of the 'id' field. - * @param value The value of 'id'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setId(Long value) { - validate(fields()[3], value); - this.id = value; - fieldSetFlags()[3] = true; - return this; + * Gets the value of the 'addresses' field. + * @return The value of the 'addresses' field. + */ + public java.util.List getAddresses() { + return addresses; } /** - * Checks whether the 'id' field has been set. - * @return True if the 'id' field has been set, false otherwise. - */ - public boolean hasId() { - return fieldSetFlags()[3]; + * Sets the value of the 'addresses' field. + * @param value the value to set. + */ + public void setAddresses(java.util.List value) { + this.addresses = value; } + /** + * Gets the value of the 'id' field. + * @return The value of the 'id' field. + */ + public Long getId() { + return id; + } /** - * Clears the value of the 'id' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearId() { - id = null; - fieldSetFlags()[3] = false; - return this; + * Sets the value of the 'id' field. + * @param value the value to set. + */ + public void setId(Long value) { + this.id = value; } /** - * Gets the value of the 'version' field. - * @return The value. - */ + * Gets the value of the 'version' field. + * @return The value of the 'version' field. + */ public Integer getVersion() { - return version; + return version; } - /** - * Sets the value of the 'version' field. - * @param value The value of 'version'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setVersion(Integer value) { - validate(fields()[4], value); - this.version = value; - fieldSetFlags()[4] = true; - return this; + * Sets the value of the 'version' field. + * @param value the value to set. + */ + public void setVersion(Integer value) { + this.version = value; } /** - * Checks whether the 'version' field has been set. - * @return True if the 'version' field has been set, false otherwise. - */ - public boolean hasVersion() { - return fieldSetFlags()[4]; + * Gets the value of the 'paymentMethods' field. + * @return The value of the 'paymentMethods' field. + */ + public java.util.List getPaymentMethods() { + return paymentMethods; } - /** - * Clears the value of the 'version' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearVersion() { - version = null; - fieldSetFlags()[4] = false; - return this; + * Sets the value of the 'paymentMethods' field. + * @param value the value to set. + */ + public void setPaymentMethods(java.util.List value) { + this.paymentMethods = value; } /** - * Gets the value of the 'paymentMethods' field. - * @return The value. - */ - public java.util.List getPaymentMethods() { - return paymentMethods; + * Creates a new CustomerEvent RecordBuilder. + * @return A new CustomerEvent RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder newBuilder() { + return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(); } - /** - * Sets the value of the 'paymentMethods' field. - * @param value The value of 'paymentMethods'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setPaymentMethods(java.util.List value) { - validate(fields()[5], value); - this.paymentMethods = value; - fieldSetFlags()[5] = true; - return this; + * Creates a new CustomerEvent RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new CustomerEvent RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder newBuilder( + io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder other) { + if (other == null) { + return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(); + } + else { + return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(other); + } } /** - * Checks whether the 'paymentMethods' field has been set. - * @return True if the 'paymentMethods' field has been set, false otherwise. - */ - public boolean hasPaymentMethods() { - return fieldSetFlags()[5]; + * Creates a new CustomerEvent RecordBuilder by copying an existing CustomerEvent + * instance. + * @param other The existing instance to copy. + * @return A new CustomerEvent RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder newBuilder( + io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent other) { + if (other == null) { + return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(); + } + else { + return new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder(other); + } } - /** - * Clears the value of the 'paymentMethods' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearPaymentMethods() { - paymentMethods = null; - fieldSetFlags()[5] = false; - return this; - } + * RecordBuilder for CustomerEvent instances. + */ + @org.apache.avro.specific.AvroGenerated + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { - @Override - @SuppressWarnings("unchecked") - public CustomerEvent build() { - try { - CustomerEvent record = new CustomerEvent(); - record.name = fieldSetFlags()[0] ? this.name : (CharSequence) defaultValue(fields()[0]); - record.email = fieldSetFlags()[1] ? this.email : (CharSequence) defaultValue(fields()[1]); - record.addresses = fieldSetFlags()[2] ? this.addresses : (java.util.List) defaultValue(fields()[2]); - record.id = fieldSetFlags()[3] ? this.id : (Long) defaultValue(fields()[3]); - record.version = fieldSetFlags()[4] ? this.version : (Integer) defaultValue(fields()[4]); - record.paymentMethods = fieldSetFlags()[5] ? this.paymentMethods : (java.util.List) defaultValue(fields()[5]); - return record; - } catch (org.apache.avro.AvroMissingFieldException e) { - throw e; - } catch (Exception e) { - throw new org.apache.avro.AvroRuntimeException(e); - } - } - } - - @SuppressWarnings("unchecked") - private static final org.apache.avro.io.DatumWriter - WRITER$ = (org.apache.avro.io.DatumWriter)MODEL$.createDatumWriter(SCHEMA$); - - @Override public void writeExternal(java.io.ObjectOutput out) - throws java.io.IOException { - WRITER$.write(this, SpecificData.getEncoder(out)); - } - - @SuppressWarnings("unchecked") - private static final org.apache.avro.io.DatumReader - READER$ = (org.apache.avro.io.DatumReader)MODEL$.createDatumReader(SCHEMA$); - - @Override public void readExternal(java.io.ObjectInput in) - throws java.io.IOException { - READER$.read(this, SpecificData.getDecoder(in)); - } - - @Override protected boolean hasCustomCoders() { return true; } - - @Override public void customEncode(org.apache.avro.io.Encoder out) - throws java.io.IOException - { - out.writeString(this.name); - - out.writeString(this.email); - - long size0 = this.addresses.size(); - out.writeArrayStart(); - out.setItemCount(size0); - long actualSize0 = 0; - for (io.zenwave360.modulith.events.scs.dtos.avro.Address e0: this.addresses) { - actualSize0++; - out.startItem(); - e0.customEncode(out); - } - out.writeArrayEnd(); - if (actualSize0 != size0) - throw new java.util.ConcurrentModificationException("Array-size written was " + size0 + ", but element count was " + actualSize0 + "."); - - if (this.id == null) { - out.writeIndex(0); - out.writeNull(); - } else { - out.writeIndex(1); - out.writeLong(this.id); - } - - if (this.version == null) { - out.writeIndex(0); - out.writeNull(); - } else { - out.writeIndex(1); - out.writeInt(this.version); - } - - long size1 = this.paymentMethods.size(); - out.writeArrayStart(); - out.setItemCount(size1); - long actualSize1 = 0; - for (io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod e1: this.paymentMethods) { - actualSize1++; - out.startItem(); - e1.customEncode(out); - } - out.writeArrayEnd(); - if (actualSize1 != size1) - throw new java.util.ConcurrentModificationException("Array-size written was " + size1 + ", but element count was " + actualSize1 + "."); - - } - - @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) - throws java.io.IOException - { - org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); - if (fieldOrder == null) { - this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null); - - this.email = in.readString(this.email instanceof Utf8 ? (Utf8)this.email : null); - - long size0 = in.readArrayStart(); - java.util.List a0 = this.addresses; - if (a0 == null) { - a0 = new SpecificData.Array((int)size0, SCHEMA$.getField("addresses").schema()); - this.addresses = a0; - } else a0.clear(); - SpecificData.Array ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array)a0 : null); - for ( ; 0 < size0; size0 = in.arrayNext()) { - for ( ; size0 != 0; size0--) { - io.zenwave360.modulith.events.scs.dtos.avro.Address e0 = (ga0 != null ? ga0.peek() : null); - if (e0 == null) { - e0 = new io.zenwave360.modulith.events.scs.dtos.avro.Address(); - } - e0.customDecode(in); - a0.add(e0); - } - } - - if (in.readIndex() != 1) { - in.readNull(); - this.id = null; - } else { - this.id = in.readLong(); - } - - if (in.readIndex() != 1) { - in.readNull(); - this.version = null; - } else { - this.version = in.readInt(); - } - - long size1 = in.readArrayStart(); - java.util.List a1 = this.paymentMethods; - if (a1 == null) { - a1 = new SpecificData.Array((int)size1, SCHEMA$.getField("paymentMethods").schema()); - this.paymentMethods = a1; - } else a1.clear(); - SpecificData.Array ga1 = (a1 instanceof SpecificData.Array ? (SpecificData.Array)a1 : null); - for ( ; 0 < size1; size1 = in.arrayNext()) { - for ( ; size1 != 0; size1--) { - io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod e1 = (ga1 != null ? ga1.peek() : null); - if (e1 == null) { - e1 = new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod(); - } - e1.customDecode(in); - a1.add(e1); - } - } - - } else { - for (int i = 0; i < 6; i++) { - switch (fieldOrder[i].pos()) { - case 0: - this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null); - break; - - case 1: - this.email = in.readString(this.email instanceof Utf8 ? (Utf8)this.email : null); - break; - - case 2: - long size0 = in.readArrayStart(); - java.util.List a0 = this.addresses; - if (a0 == null) { - a0 = new SpecificData.Array((int)size0, SCHEMA$.getField("addresses").schema()); - this.addresses = a0; - } else a0.clear(); - SpecificData.Array ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array)a0 : null); - for ( ; 0 < size0; size0 = in.arrayNext()) { - for ( ; size0 != 0; size0--) { - io.zenwave360.modulith.events.scs.dtos.avro.Address e0 = (ga0 != null ? ga0.peek() : null); - if (e0 == null) { - e0 = new io.zenwave360.modulith.events.scs.dtos.avro.Address(); - } - e0.customDecode(in); - a0.add(e0); + /** Customer name */ + private CharSequence name; + + private CharSequence email; + + private java.util.List addresses; + + private Long id; + + private Integer version; + + private java.util.List paymentMethods; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$, MODEL$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder other) { + super(other); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.email)) { + this.email = data().deepCopy(fields()[1].schema(), other.email); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + if (isValidValue(fields()[2], other.addresses)) { + this.addresses = data().deepCopy(fields()[2].schema(), other.addresses); + fieldSetFlags()[2] = other.fieldSetFlags()[2]; + } + if (isValidValue(fields()[3], other.id)) { + this.id = data().deepCopy(fields()[3].schema(), other.id); + fieldSetFlags()[3] = other.fieldSetFlags()[3]; + } + if (isValidValue(fields()[4], other.version)) { + this.version = data().deepCopy(fields()[4].schema(), other.version); + fieldSetFlags()[4] = other.fieldSetFlags()[4]; + } + if (isValidValue(fields()[5], other.paymentMethods)) { + this.paymentMethods = data().deepCopy(fields()[5].schema(), other.paymentMethods); + fieldSetFlags()[5] = other.fieldSetFlags()[5]; } - } - break; - - case 3: - if (in.readIndex() != 1) { - in.readNull(); - this.id = null; - } else { - this.id = in.readLong(); - } - break; - - case 4: - if (in.readIndex() != 1) { - in.readNull(); - this.version = null; - } else { - this.version = in.readInt(); - } - break; - - case 5: - long size1 = in.readArrayStart(); - java.util.List a1 = this.paymentMethods; - if (a1 == null) { - a1 = new SpecificData.Array((int)size1, SCHEMA$.getField("paymentMethods").schema()); - this.paymentMethods = a1; - } else a1.clear(); - SpecificData.Array ga1 = (a1 instanceof SpecificData.Array ? (SpecificData.Array)a1 : null); - for ( ; 0 < size1; size1 = in.arrayNext()) { - for ( ; size1 != 0; size1--) { - io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod e1 = (ga1 != null ? ga1.peek() : null); - if (e1 == null) { - e1 = new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod(); - } - e1.customDecode(in); - a1.add(e1); + } + + /** + * Creates a Builder by copying an existing CustomerEvent instance + * @param other The existing instance to copy. + */ + private Builder(io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent other) { + super(SCHEMA$, MODEL$); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.email)) { + this.email = data().deepCopy(fields()[1].schema(), other.email); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.addresses)) { + this.addresses = data().deepCopy(fields()[2].schema(), other.addresses); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.id)) { + this.id = data().deepCopy(fields()[3].schema(), other.id); + fieldSetFlags()[3] = true; + } + if (isValidValue(fields()[4], other.version)) { + this.version = data().deepCopy(fields()[4].schema(), other.version); + fieldSetFlags()[4] = true; } - } - break; + if (isValidValue(fields()[5], other.paymentMethods)) { + this.paymentMethods = data().deepCopy(fields()[5].schema(), other.paymentMethods); + fieldSetFlags()[5] = true; + } + } + + /** + * Gets the value of the 'name' field. Customer name + * @return The value. + */ + public CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. Customer name + * @param value The value of 'name'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setName(CharSequence value) { + validate(fields()[0], value); + this.name = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'name' field has been set. Customer name + * @return True if the 'name' field has been set, false otherwise. + */ + public boolean hasName() { + return fieldSetFlags()[0]; + } + + /** + * Clears the value of the 'name' field. Customer name + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearName() { + name = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'email' field. + * @return The value. + */ + public CharSequence getEmail() { + return email; + } + + /** + * Sets the value of the 'email' field. + * @param value The value of 'email'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setEmail(CharSequence value) { + validate(fields()[1], value); + this.email = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'email' field has been set. + * @return True if the 'email' field has been set, false otherwise. + */ + public boolean hasEmail() { + return fieldSetFlags()[1]; + } + + /** + * Clears the value of the 'email' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearEmail() { + email = null; + fieldSetFlags()[1] = false; + return this; + } + + /** + * Gets the value of the 'addresses' field. + * @return The value. + */ + public java.util.List getAddresses() { + return addresses; + } + + /** + * Sets the value of the 'addresses' field. + * @param value The value of 'addresses'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setAddresses( + java.util.List value) { + validate(fields()[2], value); + this.addresses = value; + fieldSetFlags()[2] = true; + return this; + } + + /** + * Checks whether the 'addresses' field has been set. + * @return True if the 'addresses' field has been set, false otherwise. + */ + public boolean hasAddresses() { + return fieldSetFlags()[2]; + } + + /** + * Clears the value of the 'addresses' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearAddresses() { + addresses = null; + fieldSetFlags()[2] = false; + return this; + } + + /** + * Gets the value of the 'id' field. + * @return The value. + */ + public Long getId() { + return id; + } + + /** + * Sets the value of the 'id' field. + * @param value The value of 'id'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setId(Long value) { + validate(fields()[3], value); + this.id = value; + fieldSetFlags()[3] = true; + return this; + } + + /** + * Checks whether the 'id' field has been set. + * @return True if the 'id' field has been set, false otherwise. + */ + public boolean hasId() { + return fieldSetFlags()[3]; + } + + /** + * Clears the value of the 'id' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearId() { + id = null; + fieldSetFlags()[3] = false; + return this; + } + + /** + * Gets the value of the 'version' field. + * @return The value. + */ + public Integer getVersion() { + return version; + } + + /** + * Sets the value of the 'version' field. + * @param value The value of 'version'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setVersion(Integer value) { + validate(fields()[4], value); + this.version = value; + fieldSetFlags()[4] = true; + return this; + } + + /** + * Checks whether the 'version' field has been set. + * @return True if the 'version' field has been set, false otherwise. + */ + public boolean hasVersion() { + return fieldSetFlags()[4]; + } + + /** + * Clears the value of the 'version' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearVersion() { + version = null; + fieldSetFlags()[4] = false; + return this; + } - default: - throw new java.io.IOException("Corrupt ResolvingDecoder."); + /** + * Gets the value of the 'paymentMethods' field. + * @return The value. + */ + public java.util.List getPaymentMethods() { + return paymentMethods; } - } + + /** + * Sets the value of the 'paymentMethods' field. + * @param value The value of 'paymentMethods'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder setPaymentMethods( + java.util.List value) { + validate(fields()[5], value); + this.paymentMethods = value; + fieldSetFlags()[5] = true; + return this; + } + + /** + * Checks whether the 'paymentMethods' field has been set. + * @return True if the 'paymentMethods' field has been set, false otherwise. + */ + public boolean hasPaymentMethods() { + return fieldSetFlags()[5]; + } + + /** + * Clears the value of the 'paymentMethods' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent.Builder clearPaymentMethods() { + paymentMethods = null; + fieldSetFlags()[5] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public CustomerEvent build() { + try { + CustomerEvent record = new CustomerEvent(); + record.name = fieldSetFlags()[0] ? this.name : (CharSequence) defaultValue(fields()[0]); + record.email = fieldSetFlags()[1] ? this.email : (CharSequence) defaultValue(fields()[1]); + record.addresses = fieldSetFlags()[2] ? this.addresses + : (java.util.List) defaultValue( + fields()[2]); + record.id = fieldSetFlags()[3] ? this.id : (Long) defaultValue(fields()[3]); + record.version = fieldSetFlags()[4] ? this.version : (Integer) defaultValue(fields()[4]); + record.paymentMethods = fieldSetFlags()[5] ? this.paymentMethods + : (java.util.List) defaultValue( + fields()[5]); + return record; + } + catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } + catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter WRITER$ = (org.apache.avro.io.DatumWriter) MODEL$ + .createDatumWriter(SCHEMA$); + + @Override + public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader READER$ = (org.apache.avro.io.DatumReader) MODEL$ + .createDatumReader(SCHEMA$); + + @Override + public void readExternal(java.io.ObjectInput in) throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + + @Override + protected boolean hasCustomCoders() { + return true; } - } -} + @Override + public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException { + out.writeString(this.name); + + out.writeString(this.email); + + long size0 = this.addresses.size(); + out.writeArrayStart(); + out.setItemCount(size0); + long actualSize0 = 0; + for (io.zenwave360.modulith.events.scs.dtos.avro.Address e0 : this.addresses) { + actualSize0++; + out.startItem(); + e0.customEncode(out); + } + out.writeArrayEnd(); + if (actualSize0 != size0) + throw new java.util.ConcurrentModificationException( + "Array-size written was " + size0 + ", but element count was " + actualSize0 + "."); + + if (this.id == null) { + out.writeIndex(0); + out.writeNull(); + } + else { + out.writeIndex(1); + out.writeLong(this.id); + } + if (this.version == null) { + out.writeIndex(0); + out.writeNull(); + } + else { + out.writeIndex(1); + out.writeInt(this.version); + } + long size1 = this.paymentMethods.size(); + out.writeArrayStart(); + out.setItemCount(size1); + long actualSize1 = 0; + for (io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod e1 : this.paymentMethods) { + actualSize1++; + out.startItem(); + e1.customEncode(out); + } + out.writeArrayEnd(); + if (actualSize1 != size1) + throw new java.util.ConcurrentModificationException( + "Array-size written was " + size1 + ", but element count was " + actualSize1 + "."); + } + @Override + public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null); + + this.email = in.readString(this.email instanceof Utf8 ? (Utf8) this.email : null); + + long size0 = in.readArrayStart(); + java.util.List a0 = this.addresses; + if (a0 == null) { + a0 = new SpecificData.Array((int) size0, + SCHEMA$.getField("addresses").schema()); + this.addresses = a0; + } + else + a0.clear(); + SpecificData.Array ga0 = (a0 instanceof SpecificData.Array + ? (SpecificData.Array) a0 : null); + for (; 0 < size0; size0 = in.arrayNext()) { + for (; size0 != 0; size0--) { + io.zenwave360.modulith.events.scs.dtos.avro.Address e0 = (ga0 != null ? ga0.peek() : null); + if (e0 == null) { + e0 = new io.zenwave360.modulith.events.scs.dtos.avro.Address(); + } + e0.customDecode(in); + a0.add(e0); + } + } + if (in.readIndex() != 1) { + in.readNull(); + this.id = null; + } + else { + this.id = in.readLong(); + } + if (in.readIndex() != 1) { + in.readNull(); + this.version = null; + } + else { + this.version = in.readInt(); + } + long size1 = in.readArrayStart(); + java.util.List a1 = this.paymentMethods; + if (a1 == null) { + a1 = new SpecificData.Array((int) size1, + SCHEMA$.getField("paymentMethods").schema()); + this.paymentMethods = a1; + } + else + a1.clear(); + SpecificData.Array ga1 = (a1 instanceof SpecificData.Array + ? (SpecificData.Array) a1 : null); + for (; 0 < size1; size1 = in.arrayNext()) { + for (; size1 != 0; size1--) { + io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod e1 = (ga1 != null ? ga1.peek() : null); + if (e1 == null) { + e1 = new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod(); + } + e1.customDecode(in); + a1.add(e1); + } + } + } + else { + for (int i = 0; i < 6; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null); + break; + + case 1: + this.email = in.readString(this.email instanceof Utf8 ? (Utf8) this.email : null); + break; + + case 2: + long size0 = in.readArrayStart(); + java.util.List a0 = this.addresses; + if (a0 == null) { + a0 = new SpecificData.Array( + (int) size0, SCHEMA$.getField("addresses").schema()); + this.addresses = a0; + } + else + a0.clear(); + SpecificData.Array ga0 = (a0 instanceof SpecificData.Array + ? (SpecificData.Array) a0 : null); + for (; 0 < size0; size0 = in.arrayNext()) { + for (; size0 != 0; size0--) { + io.zenwave360.modulith.events.scs.dtos.avro.Address e0 = (ga0 != null ? ga0.peek() + : null); + if (e0 == null) { + e0 = new io.zenwave360.modulith.events.scs.dtos.avro.Address(); + } + e0.customDecode(in); + a0.add(e0); + } + } + break; + + case 3: + if (in.readIndex() != 1) { + in.readNull(); + this.id = null; + } + else { + this.id = in.readLong(); + } + break; + + case 4: + if (in.readIndex() != 1) { + in.readNull(); + this.version = null; + } + else { + this.version = in.readInt(); + } + break; + + case 5: + long size1 = in.readArrayStart(); + java.util.List a1 = this.paymentMethods; + if (a1 == null) { + a1 = new SpecificData.Array( + (int) size1, SCHEMA$.getField("paymentMethods").schema()); + this.paymentMethods = a1; + } + else + a1.clear(); + SpecificData.Array ga1 = (a1 instanceof SpecificData.Array + ? (SpecificData.Array) a1 + : null); + for (; 0 < size1; size1 = in.arrayNext()) { + for (; size1 != 0; size1--) { + io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod e1 = (ga1 != null ? ga1.peek() + : null); + if (e1 == null) { + e1 = new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod(); + } + e1.customDecode(in); + a1.add(e1); + } + } + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethod.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethod.java index 54277a8..6ec4ac3 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethod.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethod.java @@ -12,466 +12,488 @@ import org.apache.avro.util.Utf8; @org.apache.avro.specific.AvroGenerated -public class PaymentMethod extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = -3545422545868948468L; - - - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"PaymentMethod\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"type\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentMethodType\",\"symbols\":[\"VISA\",\"MASTERCARD\"]}},{\"name\":\"cardNumber\",\"type\":\"string\"}]}"); - public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } - - private static final SpecificData MODEL$ = new SpecificData(); - - private static final BinaryMessageEncoder ENCODER = - new BinaryMessageEncoder<>(MODEL$, SCHEMA$); - - private static final BinaryMessageDecoder DECODER = - new BinaryMessageDecoder<>(MODEL$, SCHEMA$); - - /** - * Return the BinaryMessageEncoder instance used by this class. - * @return the message encoder used by this class - */ - public static BinaryMessageEncoder getEncoder() { - return ENCODER; - } - - /** - * Return the BinaryMessageDecoder instance used by this class. - * @return the message decoder used by this class - */ - public static BinaryMessageDecoder getDecoder() { - return DECODER; - } - - /** - * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. - * @param resolver a {@link SchemaStore} used to find schemas by fingerprint - * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore - */ - public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { - return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver); - } - - /** - * Serializes this PaymentMethod to a ByteBuffer. - * @return a buffer holding the serialized data for this instance - * @throws java.io.IOException if this instance could not be serialized - */ - public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { - return ENCODER.encode(this); - } - - /** - * Deserializes a PaymentMethod from a ByteBuffer. - * @param b a byte buffer holding serialized data for an instance of this class - * @return a PaymentMethod instance decoded from the given buffer - * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class - */ - public static PaymentMethod fromByteBuffer( - java.nio.ByteBuffer b) throws java.io.IOException { - return DECODER.decode(b); - } - - private int id; - private io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType type; - private CharSequence cardNumber; - - /** - * Default constructor. Note that this does not initialize fields - * to their default values from the schema. If that is desired then - * one should use newBuilder(). - */ - public PaymentMethod() {} - - /** - * All-args constructor. - * @param id The new value for id - * @param type The new value for type - * @param cardNumber The new value for cardNumber - */ - public PaymentMethod(Integer id, io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType type, CharSequence cardNumber) { - this.id = id; - this.type = type; - this.cardNumber = cardNumber; - } - - @Override - public SpecificData getSpecificData() { return MODEL$; } - - @Override - public org.apache.avro.Schema getSchema() { return SCHEMA$; } - - // Used by DatumWriter. Applications should not call. - @Override - public Object get(int field$) { - switch (field$) { - case 0: return id; - case 1: return type; - case 2: return cardNumber; - default: throw new IndexOutOfBoundsException("Invalid index: " + field$); - } - } - - // Used by DatumReader. Applications should not call. - @Override - @SuppressWarnings(value="unchecked") - public void put(int field$, Object value$) { - switch (field$) { - case 0: id = (Integer)value$; break; - case 1: type = (io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType)value$; break; - case 2: cardNumber = (CharSequence)value$; break; - default: throw new IndexOutOfBoundsException("Invalid index: " + field$); - } - } - - /** - * Gets the value of the 'id' field. - * @return The value of the 'id' field. - */ - public int getId() { - return id; - } - - - /** - * Sets the value of the 'id' field. - * @param value the value to set. - */ - public void setId(int value) { - this.id = value; - } - - /** - * Gets the value of the 'type' field. - * @return The value of the 'type' field. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType getType() { - return type; - } - - - /** - * Sets the value of the 'type' field. - * @param value the value to set. - */ - public void setType(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType value) { - this.type = value; - } - - /** - * Gets the value of the 'cardNumber' field. - * @return The value of the 'cardNumber' field. - */ - public CharSequence getCardNumber() { - return cardNumber; - } - - - /** - * Sets the value of the 'cardNumber' field. - * @param value the value to set. - */ - public void setCardNumber(CharSequence value) { - this.cardNumber = value; - } - - /** - * Creates a new PaymentMethod RecordBuilder. - * @return A new PaymentMethod RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder newBuilder() { - return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(); - } - - /** - * Creates a new PaymentMethod RecordBuilder by copying an existing Builder. - * @param other The existing builder to copy. - * @return A new PaymentMethod RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder newBuilder(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder other) { - if (other == null) { - return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(); - } else { - return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(other); - } - } - - /** - * Creates a new PaymentMethod RecordBuilder by copying an existing PaymentMethod instance. - * @param other The existing instance to copy. - * @return A new PaymentMethod RecordBuilder - */ - public static io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder newBuilder(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod other) { - if (other == null) { - return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(); - } else { - return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(other); - } - } +public class PaymentMethod extends org.apache.avro.specific.SpecificRecordBase + implements org.apache.avro.specific.SpecificRecord { - /** - * RecordBuilder for PaymentMethod instances. - */ - @org.apache.avro.specific.AvroGenerated - public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase - implements org.apache.avro.data.RecordBuilder { + private static final long serialVersionUID = -3545422545868948468L; - private int id; - private io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType type; - private CharSequence cardNumber; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( + "{\"type\":\"record\",\"name\":\"PaymentMethod\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"type\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentMethodType\",\"symbols\":[\"VISA\",\"MASTERCARD\"]}},{\"name\":\"cardNumber\",\"type\":\"string\"}]}"); - /** Creates a new Builder */ - private Builder() { - super(SCHEMA$, MODEL$); + public static org.apache.avro.Schema getClassSchema() { + return SCHEMA$; } + private static final SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = new BinaryMessageEncoder<>(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = new BinaryMessageDecoder<>(MODEL$, SCHEMA$); + /** - * Creates a Builder by copying an existing Builder. - * @param other The existing Builder to copy. + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class */ - private Builder(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder other) { - super(other); - if (isValidValue(fields()[0], other.id)) { - this.id = data().deepCopy(fields()[0].schema(), other.id); - fieldSetFlags()[0] = other.fieldSetFlags()[0]; - } - if (isValidValue(fields()[1], other.type)) { - this.type = data().deepCopy(fields()[1].schema(), other.type); - fieldSetFlags()[1] = other.fieldSetFlags()[1]; - } - if (isValidValue(fields()[2], other.cardNumber)) { - this.cardNumber = data().deepCopy(fields()[2].schema(), other.cardNumber); - fieldSetFlags()[2] = other.fieldSetFlags()[2]; - } + public static BinaryMessageEncoder getEncoder() { + return ENCODER; } /** - * Creates a Builder by copying an existing PaymentMethod instance - * @param other The existing instance to copy. + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class */ - private Builder(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod other) { - super(SCHEMA$, MODEL$); - if (isValidValue(fields()[0], other.id)) { - this.id = data().deepCopy(fields()[0].schema(), other.id); - fieldSetFlags()[0] = true; - } - if (isValidValue(fields()[1], other.type)) { - this.type = data().deepCopy(fields()[1].schema(), other.type); - fieldSetFlags()[1] = true; - } - if (isValidValue(fields()[2], other.cardNumber)) { - this.cardNumber = data().deepCopy(fields()[2].schema(), other.cardNumber); - fieldSetFlags()[2] = true; - } + public static BinaryMessageDecoder getDecoder() { + return DECODER; } /** - * Gets the value of the 'id' field. - * @return The value. - */ - public int getId() { - return id; + * Create a new BinaryMessageDecoder instance for this class that uses the specified + * {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given + * SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver); } - /** - * Sets the value of the 'id' field. - * @param value The value of 'id'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder setId(int value) { - validate(fields()[0], value); - this.id = value; - fieldSetFlags()[0] = true; - return this; + * Serializes this PaymentMethod to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); } /** - * Checks whether the 'id' field has been set. - * @return True if the 'id' field has been set, false otherwise. - */ - public boolean hasId() { - return fieldSetFlags()[0]; + * Deserializes a PaymentMethod from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a PaymentMethod instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an + * instance of this class + */ + public static PaymentMethod fromByteBuffer(java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); } + private int id; + + private io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType type; + + private CharSequence cardNumber; /** - * Clears the value of the 'id' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder clearId() { - fieldSetFlags()[0] = false; - return this; + * Default constructor. Note that this does not initialize fields to their default + * values from the schema. If that is desired then one should use + * newBuilder(). + */ + public PaymentMethod() { } /** - * Gets the value of the 'type' field. - * @return The value. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType getType() { - return type; + * All-args constructor. + * @param id The new value for id + * @param type The new value for type + * @param cardNumber The new value for cardNumber + */ + public PaymentMethod(Integer id, io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType type, + CharSequence cardNumber) { + this.id = id; + this.type = type; + this.cardNumber = cardNumber; } + @Override + public SpecificData getSpecificData() { + return MODEL$; + } + + @Override + public org.apache.avro.Schema getSchema() { + return SCHEMA$; + } + + // Used by DatumWriter. Applications should not call. + @Override + public Object get(int field$) { + switch (field$) { + case 0: + return id; + case 1: + return type; + case 2: + return cardNumber; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } + + // Used by DatumReader. Applications should not call. + @Override + @SuppressWarnings(value = "unchecked") + public void put(int field$, Object value$) { + switch (field$) { + case 0: + id = (Integer) value$; + break; + case 1: + type = (io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType) value$; + break; + case 2: + cardNumber = (CharSequence) value$; + break; + default: + throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } /** - * Sets the value of the 'type' field. - * @param value The value of 'type'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder setType(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType value) { - validate(fields()[1], value); - this.type = value; - fieldSetFlags()[1] = true; - return this; + * Gets the value of the 'id' field. + * @return The value of the 'id' field. + */ + public int getId() { + return id; } /** - * Checks whether the 'type' field has been set. - * @return True if the 'type' field has been set, false otherwise. - */ - public boolean hasType() { - return fieldSetFlags()[1]; + * Sets the value of the 'id' field. + * @param value the value to set. + */ + public void setId(int value) { + this.id = value; } + /** + * Gets the value of the 'type' field. + * @return The value of the 'type' field. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType getType() { + return type; + } /** - * Clears the value of the 'type' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder clearType() { - type = null; - fieldSetFlags()[1] = false; - return this; + * Sets the value of the 'type' field. + * @param value the value to set. + */ + public void setType(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType value) { + this.type = value; } /** - * Gets the value of the 'cardNumber' field. - * @return The value. - */ + * Gets the value of the 'cardNumber' field. + * @return The value of the 'cardNumber' field. + */ public CharSequence getCardNumber() { - return cardNumber; + return cardNumber; } - /** - * Sets the value of the 'cardNumber' field. - * @param value The value of 'cardNumber'. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder setCardNumber(CharSequence value) { - validate(fields()[2], value); - this.cardNumber = value; - fieldSetFlags()[2] = true; - return this; + * Sets the value of the 'cardNumber' field. + * @param value the value to set. + */ + public void setCardNumber(CharSequence value) { + this.cardNumber = value; } /** - * Checks whether the 'cardNumber' field has been set. - * @return True if the 'cardNumber' field has been set, false otherwise. - */ - public boolean hasCardNumber() { - return fieldSetFlags()[2]; + * Creates a new PaymentMethod RecordBuilder. + * @return A new PaymentMethod RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder newBuilder() { + return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(); } - /** - * Clears the value of the 'cardNumber' field. - * @return This builder. - */ - public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder clearCardNumber() { - cardNumber = null; - fieldSetFlags()[2] = false; - return this; + * Creates a new PaymentMethod RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new PaymentMethod RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder newBuilder( + io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder other) { + if (other == null) { + return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(); + } + else { + return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(other); + } } - @Override - @SuppressWarnings("unchecked") - public PaymentMethod build() { - try { - PaymentMethod record = new PaymentMethod(); - record.id = fieldSetFlags()[0] ? this.id : (Integer) defaultValue(fields()[0]); - record.type = fieldSetFlags()[1] ? this.type : (io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType) defaultValue(fields()[1]); - record.cardNumber = fieldSetFlags()[2] ? this.cardNumber : (CharSequence) defaultValue(fields()[2]); - return record; - } catch (org.apache.avro.AvroMissingFieldException e) { - throw e; - } catch (Exception e) { - throw new org.apache.avro.AvroRuntimeException(e); - } + /** + * Creates a new PaymentMethod RecordBuilder by copying an existing PaymentMethod + * instance. + * @param other The existing instance to copy. + * @return A new PaymentMethod RecordBuilder + */ + public static io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder newBuilder( + io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod other) { + if (other == null) { + return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(); + } + else { + return new io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder(other); + } } - } - @SuppressWarnings("unchecked") - private static final org.apache.avro.io.DatumWriter - WRITER$ = (org.apache.avro.io.DatumWriter)MODEL$.createDatumWriter(SCHEMA$); + /** + * RecordBuilder for PaymentMethod instances. + */ + @org.apache.avro.specific.AvroGenerated + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private int id; + + private io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType type; - @Override public void writeExternal(java.io.ObjectOutput out) - throws java.io.IOException { - WRITER$.write(this, SpecificData.getEncoder(out)); - } + private CharSequence cardNumber; - @SuppressWarnings("unchecked") - private static final org.apache.avro.io.DatumReader - READER$ = (org.apache.avro.io.DatumReader)MODEL$.createDatumReader(SCHEMA$); + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$, MODEL$); + } - @Override public void readExternal(java.io.ObjectInput in) - throws java.io.IOException { - READER$.read(this, SpecificData.getDecoder(in)); - } + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder other) { + super(other); + if (isValidValue(fields()[0], other.id)) { + this.id = data().deepCopy(fields()[0].schema(), other.id); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.type)) { + this.type = data().deepCopy(fields()[1].schema(), other.type); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + if (isValidValue(fields()[2], other.cardNumber)) { + this.cardNumber = data().deepCopy(fields()[2].schema(), other.cardNumber); + fieldSetFlags()[2] = other.fieldSetFlags()[2]; + } + } - @Override protected boolean hasCustomCoders() { return true; } + /** + * Creates a Builder by copying an existing PaymentMethod instance + * @param other The existing instance to copy. + */ + private Builder(io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod other) { + super(SCHEMA$, MODEL$); + if (isValidValue(fields()[0], other.id)) { + this.id = data().deepCopy(fields()[0].schema(), other.id); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.type)) { + this.type = data().deepCopy(fields()[1].schema(), other.type); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.cardNumber)) { + this.cardNumber = data().deepCopy(fields()[2].schema(), other.cardNumber); + fieldSetFlags()[2] = true; + } + } - @Override public void customEncode(org.apache.avro.io.Encoder out) - throws java.io.IOException - { - out.writeInt(this.id); + /** + * Gets the value of the 'id' field. + * @return The value. + */ + public int getId() { + return id; + } - out.writeEnum(this.type.ordinal()); + /** + * Sets the value of the 'id' field. + * @param value The value of 'id'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder setId(int value) { + validate(fields()[0], value); + this.id = value; + fieldSetFlags()[0] = true; + return this; + } - out.writeString(this.cardNumber); + /** + * Checks whether the 'id' field has been set. + * @return True if the 'id' field has been set, false otherwise. + */ + public boolean hasId() { + return fieldSetFlags()[0]; + } - } + /** + * Clears the value of the 'id' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder clearId() { + fieldSetFlags()[0] = false; + return this; + } - @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) - throws java.io.IOException - { - org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); - if (fieldOrder == null) { - this.id = in.readInt(); + /** + * Gets the value of the 'type' field. + * @return The value. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType getType() { + return type; + } - this.type = io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType.values()[in.readEnum()]; + /** + * Sets the value of the 'type' field. + * @param value The value of 'type'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder setType( + io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType value) { + validate(fields()[1], value); + this.type = value; + fieldSetFlags()[1] = true; + return this; + } - this.cardNumber = in.readString(this.cardNumber instanceof Utf8 ? (Utf8)this.cardNumber : null); + /** + * Checks whether the 'type' field has been set. + * @return True if the 'type' field has been set, false otherwise. + */ + public boolean hasType() { + return fieldSetFlags()[1]; + } - } else { - for (int i = 0; i < 3; i++) { - switch (fieldOrder[i].pos()) { - case 0: - this.id = in.readInt(); - break; + /** + * Clears the value of the 'type' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder clearType() { + type = null; + fieldSetFlags()[1] = false; + return this; + } - case 1: - this.type = io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType.values()[in.readEnum()]; - break; + /** + * Gets the value of the 'cardNumber' field. + * @return The value. + */ + public CharSequence getCardNumber() { + return cardNumber; + } - case 2: - this.cardNumber = in.readString(this.cardNumber instanceof Utf8 ? (Utf8)this.cardNumber : null); - break; + /** + * Sets the value of the 'cardNumber' field. + * @param value The value of 'cardNumber'. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder setCardNumber(CharSequence value) { + validate(fields()[2], value); + this.cardNumber = value; + fieldSetFlags()[2] = true; + return this; + } - default: - throw new java.io.IOException("Corrupt ResolvingDecoder."); + /** + * Checks whether the 'cardNumber' field has been set. + * @return True if the 'cardNumber' field has been set, false otherwise. + */ + public boolean hasCardNumber() { + return fieldSetFlags()[2]; } - } + + /** + * Clears the value of the 'cardNumber' field. + * @return This builder. + */ + public io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethod.Builder clearCardNumber() { + cardNumber = null; + fieldSetFlags()[2] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public PaymentMethod build() { + try { + PaymentMethod record = new PaymentMethod(); + record.id = fieldSetFlags()[0] ? this.id : (Integer) defaultValue(fields()[0]); + record.type = fieldSetFlags()[1] ? this.type + : (io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType) defaultValue(fields()[1]); + record.cardNumber = fieldSetFlags()[2] ? this.cardNumber : (CharSequence) defaultValue(fields()[2]); + return record; + } + catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } + catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } - } -} + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter WRITER$ = (org.apache.avro.io.DatumWriter) MODEL$ + .createDatumWriter(SCHEMA$); + @Override + public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader READER$ = (org.apache.avro.io.DatumReader) MODEL$ + .createDatumReader(SCHEMA$); + @Override + public void readExternal(java.io.ObjectInput in) throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + @Override + protected boolean hasCustomCoders() { + return true; + } + + @Override + public void customEncode(org.apache.avro.io.Encoder out) throws java.io.IOException { + out.writeInt(this.id); + + out.writeEnum(this.type.ordinal()); + + out.writeString(this.cardNumber); + + } + @Override + public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.IOException { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.id = in.readInt(); + this.type = io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType.values()[in.readEnum()]; + this.cardNumber = in.readString(this.cardNumber instanceof Utf8 ? (Utf8) this.cardNumber : null); + } + else { + for (int i = 0; i < 3; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.id = in.readInt(); + break; + + case 1: + this.type = io.zenwave360.modulith.events.scs.dtos.avro.PaymentMethodType.values()[in + .readEnum()]; + break; + + case 2: + this.cardNumber = in + .readString(this.cardNumber instanceof Utf8 ? (Utf8) this.cardNumber : null); + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethodType.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethodType.java index 2b92772..d581596 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethodType.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/avro/PaymentMethodType.java @@ -4,12 +4,22 @@ * DO NOT EDIT DIRECTLY */ package io.zenwave360.modulith.events.scs.dtos.avro; + @org.apache.avro.specific.AvroGenerated public enum PaymentMethodType implements org.apache.avro.generic.GenericEnumSymbol { - VISA, MASTERCARD ; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"PaymentMethodType\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"symbols\":[\"VISA\",\"MASTERCARD\"]}"); - public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } - @Override - public org.apache.avro.Schema getSchema() { return SCHEMA$; } + VISA, MASTERCARD; + + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( + "{\"type\":\"enum\",\"name\":\"PaymentMethodType\",\"namespace\":\"io.zenwave360.modulith.events.scs.dtos.avro\",\"symbols\":[\"VISA\",\"MASTERCARD\"]}"); + + public static org.apache.avro.Schema getClassSchema() { + return SCHEMA$; + } + + @Override + public org.apache.avro.Schema getSchema() { + return SCHEMA$; + } + } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/Address.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/Address.java index ab727d9..e6d4f04 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/Address.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/Address.java @@ -11,12 +11,8 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "street", - "city" -}) -public class Address implements Serializable -{ +@JsonPropertyOrder({ "street", "city" }) +public class Address implements Serializable { /** * @@ -27,6 +23,7 @@ public class Address implements Serializable @Size(max = 254) @NotNull private String street; + /** * * (Required) @@ -36,10 +33,13 @@ public class Address implements Serializable @Size(max = 254) @NotNull private String city; + @JsonIgnore @Valid private Map additionalProperties = new LinkedHashMap(); + protected final static Object NOT_FOUND_VALUE = new Object(); + private final static long serialVersionUID = -2054487487628445756L; /** @@ -111,19 +111,25 @@ protected boolean declaredProperty(String name, Object value) { if ("street".equals(name)) { if (value instanceof String) { setStreet(((String) value)); - } else { - throw new IllegalArgumentException(("property \"street\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException(("property \"street\" is of type \"java.lang.String\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { if ("city".equals(name)) { if (value instanceof String) { setCity(((String) value)); - } else { - throw new IllegalArgumentException(("property \"city\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException(("property \"city\" is of type \"java.lang.String\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { return false; } } @@ -132,23 +138,24 @@ protected boolean declaredProperty(String name, Object value) { protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { if ("street".equals(name)) { return getStreet(); - } else { + } + else { if ("city".equals(name)) { return getCity(); - } else { + } + else { return notFoundValue; } } } - @SuppressWarnings({ - "unchecked" - }) - publicT get(String name) { + @SuppressWarnings({ "unchecked" }) + public T get(String name) { Object value = declaredPropertyOrNotFound(name, Address.NOT_FOUND_VALUE); - if (Address.NOT_FOUND_VALUE!= value) { + if (Address.NOT_FOUND_VALUE != value) { return ((T) value); - } else { + } + else { return ((T) getAdditionalProperties().get(name)); } } @@ -169,22 +176,26 @@ public Address with(String name, Object value) { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(Address.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); + sb.append(Address.class.getName()) + .append('@') + .append(Integer.toHexString(System.identityHashCode(this))) + .append('['); sb.append("street"); sb.append('='); - sb.append(((this.street == null)?"":this.street)); + sb.append(((this.street == null) ? "" : this.street)); sb.append(','); sb.append("city"); sb.append('='); - sb.append(((this.city == null)?"":this.city)); + sb.append(((this.city == null) ? "" : this.city)); sb.append(','); sb.append("additionalProperties"); sb.append('='); - sb.append(((this.additionalProperties == null)?"":this.additionalProperties)); + sb.append(((this.additionalProperties == null) ? "" : this.additionalProperties)); sb.append(','); - if (sb.charAt((sb.length()- 1)) == ',') { - sb.setCharAt((sb.length()- 1), ']'); - } else { + if (sb.charAt((sb.length() - 1)) == ',') { + sb.setCharAt((sb.length() - 1), ']'); + } + else { sb.append(']'); } return sb.toString(); @@ -193,9 +204,9 @@ public String toString() { @Override public int hashCode() { int result = 1; - result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode())); - result = ((result* 31)+((this.city == null)? 0 :this.city.hashCode())); - result = ((result* 31)+((this.street == null)? 0 :this.street.hashCode())); + result = ((result * 31) + ((this.additionalProperties == null) ? 0 : this.additionalProperties.hashCode())); + result = ((result * 31) + ((this.city == null) ? 0 : this.city.hashCode())); + result = ((result * 31) + ((this.street == null) ? 0 : this.street.hashCode())); return result; } @@ -208,7 +219,10 @@ public boolean equals(Object other) { return false; } Address rhs = ((Address) other); - return ((((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties)))&&((this.city == rhs.city)||((this.city!= null)&&this.city.equals(rhs.city))))&&((this.street == rhs.street)||((this.street!= null)&&this.street.equals(rhs.street)))); + return ((((this.additionalProperties == rhs.additionalProperties) + || ((this.additionalProperties != null) && this.additionalProperties.equals(rhs.additionalProperties))) + && ((this.city == rhs.city) || ((this.city != null) && this.city.equals(rhs.city)))) + && ((this.street == rhs.street) || ((this.street != null) && this.street.equals(rhs.street)))); } } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/CustomerEvent.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/CustomerEvent.java index 099676c..867c3c8 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/CustomerEvent.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/CustomerEvent.java @@ -14,20 +14,11 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "name", - "email", - "addresses", - "id", - "version", - "paymentMethods" -}) -public class CustomerEvent implements Serializable -{ +@JsonPropertyOrder({ "name", "email", "addresses", "id", "version", "paymentMethods" }) +public class CustomerEvent implements Serializable { /** - * Customer name - * (Required) + * Customer name (Required) * */ @JsonProperty("name") @@ -35,6 +26,7 @@ public class CustomerEvent implements Serializable @Size(max = 254) @NotNull private String name; + /** * * (Required) @@ -45,25 +37,31 @@ public class CustomerEvent implements Serializable @Size(max = 254) @NotNull private String email; + @JsonProperty("addresses") @Valid private List
addresses = new ArrayList
(); + @JsonProperty("id") private Long id; + @JsonProperty("version") private Long version; + @JsonProperty("paymentMethods") @Valid private List paymentMethods = new ArrayList(); + @JsonIgnore @Valid private Map additionalProperties = new LinkedHashMap(); + protected final static Object NOT_FOUND_VALUE = new Object(); + private final static long serialVersionUID = 2415813790372213850L; /** - * Customer name - * (Required) + * Customer name (Required) * */ @JsonProperty("name") @@ -72,8 +70,7 @@ public String getName() { } /** - * Customer name - * (Required) + * Customer name (Required) * */ @JsonProperty("name") @@ -190,51 +187,73 @@ protected boolean declaredProperty(String name, Object value) { if ("name".equals(name)) { if (value instanceof String) { setName(((String) value)); - } else { - throw new IllegalArgumentException(("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException( + ("property \"name\" is of type \"java.lang.String\", but got " + value.getClass().toString())); } return true; - } else { + } + else { if ("email".equals(name)) { if (value instanceof String) { setEmail(((String) value)); - } else { - throw new IllegalArgumentException(("property \"email\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException(("property \"email\" is of type \"java.lang.String\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { if ("addresses".equals(name)) { if (value instanceof List) { - setAddresses(((List
) value)); - } else { - throw new IllegalArgumentException(("property \"addresses\" is of type \"java.util.List\", but got "+ value.getClass().toString())); + setAddresses(((List
) value)); + } + else { + throw new IllegalArgumentException( + ("property \"addresses\" is of type \"java.util.List\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { if ("id".equals(name)) { if (value instanceof Long) { setId(((Long) value)); - } else { - throw new IllegalArgumentException(("property \"id\" is of type \"java.lang.Long\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException( + ("property \"id\" is of type \"java.lang.Long\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { if ("version".equals(name)) { if (value instanceof Long) { setVersion(((Long) value)); - } else { - throw new IllegalArgumentException(("property \"version\" is of type \"java.lang.Long\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException( + ("property \"version\" is of type \"java.lang.Long\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { if ("paymentMethods".equals(name)) { if (value instanceof List) { - setPaymentMethods(((List ) value)); - } else { - throw new IllegalArgumentException(("property \"paymentMethods\" is of type \"java.util.List\", but got "+ value.getClass().toString())); + setPaymentMethods(((List) value)); + } + else { + throw new IllegalArgumentException( + ("property \"paymentMethods\" is of type \"java.util.List\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { return false; } } @@ -247,22 +266,28 @@ protected boolean declaredProperty(String name, Object value) { protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { if ("name".equals(name)) { return getName(); - } else { + } + else { if ("email".equals(name)) { return getEmail(); - } else { + } + else { if ("addresses".equals(name)) { return getAddresses(); - } else { + } + else { if ("id".equals(name)) { return getId(); - } else { + } + else { if ("version".equals(name)) { return getVersion(); - } else { + } + else { if ("paymentMethods".equals(name)) { return getPaymentMethods(); - } else { + } + else { return notFoundValue; } } @@ -272,14 +297,13 @@ protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { } } - @SuppressWarnings({ - "unchecked" - }) - publicT get(String name) { + @SuppressWarnings({ "unchecked" }) + public T get(String name) { Object value = declaredPropertyOrNotFound(name, CustomerEvent.NOT_FOUND_VALUE); - if (CustomerEvent.NOT_FOUND_VALUE!= value) { + if (CustomerEvent.NOT_FOUND_VALUE != value) { return ((T) value); - } else { + } + else { return ((T) getAdditionalProperties().get(name)); } } @@ -300,38 +324,42 @@ public CustomerEvent with(String name, Object value) { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(CustomerEvent.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); + sb.append(CustomerEvent.class.getName()) + .append('@') + .append(Integer.toHexString(System.identityHashCode(this))) + .append('['); sb.append("name"); sb.append('='); - sb.append(((this.name == null)?"":this.name)); + sb.append(((this.name == null) ? "" : this.name)); sb.append(','); sb.append("email"); sb.append('='); - sb.append(((this.email == null)?"":this.email)); + sb.append(((this.email == null) ? "" : this.email)); sb.append(','); sb.append("addresses"); sb.append('='); - sb.append(((this.addresses == null)?"":this.addresses)); + sb.append(((this.addresses == null) ? "" : this.addresses)); sb.append(','); sb.append("id"); sb.append('='); - sb.append(((this.id == null)?"":this.id)); + sb.append(((this.id == null) ? "" : this.id)); sb.append(','); sb.append("version"); sb.append('='); - sb.append(((this.version == null)?"":this.version)); + sb.append(((this.version == null) ? "" : this.version)); sb.append(','); sb.append("paymentMethods"); sb.append('='); - sb.append(((this.paymentMethods == null)?"":this.paymentMethods)); + sb.append(((this.paymentMethods == null) ? "" : this.paymentMethods)); sb.append(','); sb.append("additionalProperties"); sb.append('='); - sb.append(((this.additionalProperties == null)?"":this.additionalProperties)); + sb.append(((this.additionalProperties == null) ? "" : this.additionalProperties)); sb.append(','); - if (sb.charAt((sb.length()- 1)) == ',') { - sb.setCharAt((sb.length()- 1), ']'); - } else { + if (sb.charAt((sb.length() - 1)) == ',') { + sb.setCharAt((sb.length() - 1), ']'); + } + else { sb.append(']'); } return sb.toString(); @@ -340,13 +368,13 @@ public String toString() { @Override public int hashCode() { int result = 1; - result = ((result* 31)+((this.addresses == null)? 0 :this.addresses.hashCode())); - result = ((result* 31)+((this.paymentMethods == null)? 0 :this.paymentMethods.hashCode())); - result = ((result* 31)+((this.name == null)? 0 :this.name.hashCode())); - result = ((result* 31)+((this.id == null)? 0 :this.id.hashCode())); - result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode())); - result = ((result* 31)+((this.version == null)? 0 :this.version.hashCode())); - result = ((result* 31)+((this.email == null)? 0 :this.email.hashCode())); + result = ((result * 31) + ((this.addresses == null) ? 0 : this.addresses.hashCode())); + result = ((result * 31) + ((this.paymentMethods == null) ? 0 : this.paymentMethods.hashCode())); + result = ((result * 31) + ((this.name == null) ? 0 : this.name.hashCode())); + result = ((result * 31) + ((this.id == null) ? 0 : this.id.hashCode())); + result = ((result * 31) + ((this.additionalProperties == null) ? 0 : this.additionalProperties.hashCode())); + result = ((result * 31) + ((this.version == null) ? 0 : this.version.hashCode())); + result = ((result * 31) + ((this.email == null) ? 0 : this.email.hashCode())); return result; } @@ -359,7 +387,16 @@ public boolean equals(Object other) { return false; } CustomerEvent rhs = ((CustomerEvent) other); - return ((((((((this.addresses == rhs.addresses)||((this.addresses!= null)&&this.addresses.equals(rhs.addresses)))&&((this.paymentMethods == rhs.paymentMethods)||((this.paymentMethods!= null)&&this.paymentMethods.equals(rhs.paymentMethods))))&&((this.name == rhs.name)||((this.name!= null)&&this.name.equals(rhs.name))))&&((this.id == rhs.id)||((this.id!= null)&&this.id.equals(rhs.id))))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties))))&&((this.version == rhs.version)||((this.version!= null)&&this.version.equals(rhs.version))))&&((this.email == rhs.email)||((this.email!= null)&&this.email.equals(rhs.email)))); + return ((((((((this.addresses == rhs.addresses) + || ((this.addresses != null) && this.addresses.equals(rhs.addresses))) + && ((this.paymentMethods == rhs.paymentMethods) + || ((this.paymentMethods != null) && this.paymentMethods.equals(rhs.paymentMethods)))) + && ((this.name == rhs.name) || ((this.name != null) && this.name.equals(rhs.name)))) + && ((this.id == rhs.id) || ((this.id != null) && this.id.equals(rhs.id)))) + && ((this.additionalProperties == rhs.additionalProperties) || ((this.additionalProperties != null) + && this.additionalProperties.equals(rhs.additionalProperties)))) + && ((this.version == rhs.version) || ((this.version != null) && this.version.equals(rhs.version)))) + && ((this.email == rhs.email) || ((this.email != null) && this.email.equals(rhs.email)))); } } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethod.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethod.java index cb9100e..5814f6d 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethod.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethod.java @@ -10,16 +10,12 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "id", - "type", - "cardNumber" -}) -public class PaymentMethod implements Serializable -{ +@JsonPropertyOrder({ "id", "type", "cardNumber" }) +public class PaymentMethod implements Serializable { @JsonProperty("id") private Long id; + /** * * (Required) @@ -28,6 +24,7 @@ public class PaymentMethod implements Serializable @JsonProperty("type") @NotNull private PaymentMethodType type; + /** * * (Required) @@ -36,10 +33,13 @@ public class PaymentMethod implements Serializable @JsonProperty("cardNumber") @NotNull private String cardNumber; + @JsonIgnore @Valid private Map additionalProperties = new LinkedHashMap(); + protected final static Object NOT_FOUND_VALUE = new Object(); + private final static long serialVersionUID = -8629217294484723648L; @JsonProperty("id") @@ -126,27 +126,38 @@ protected boolean declaredProperty(String name, Object value) { if ("id".equals(name)) { if (value instanceof Long) { setId(((Long) value)); - } else { - throw new IllegalArgumentException(("property \"id\" is of type \"java.lang.Long\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException( + ("property \"id\" is of type \"java.lang.Long\", but got " + value.getClass().toString())); } return true; - } else { + } + else { if ("type".equals(name)) { if (value instanceof PaymentMethodType) { setType(((PaymentMethodType) value)); - } else { - throw new IllegalArgumentException(("property \"type\" is of type \"io.zenwave360.example.core.outbound.events.dtos.PaymentMethodType\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException( + ("property \"type\" is of type \"io.zenwave360.example.core.outbound.events.dtos.PaymentMethodType\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { if ("cardNumber".equals(name)) { if (value instanceof String) { setCardNumber(((String) value)); - } else { - throw new IllegalArgumentException(("property \"cardNumber\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); + } + else { + throw new IllegalArgumentException( + ("property \"cardNumber\" is of type \"java.lang.String\", but got " + + value.getClass().toString())); } return true; - } else { + } + else { return false; } } @@ -156,27 +167,29 @@ protected boolean declaredProperty(String name, Object value) { protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) { if ("id".equals(name)) { return getId(); - } else { + } + else { if ("type".equals(name)) { return getType(); - } else { + } + else { if ("cardNumber".equals(name)) { return getCardNumber(); - } else { + } + else { return notFoundValue; } } } } - @SuppressWarnings({ - "unchecked" - }) - publicT get(String name) { + @SuppressWarnings({ "unchecked" }) + public T get(String name) { Object value = declaredPropertyOrNotFound(name, PaymentMethod.NOT_FOUND_VALUE); - if (PaymentMethod.NOT_FOUND_VALUE!= value) { + if (PaymentMethod.NOT_FOUND_VALUE != value) { return ((T) value); - } else { + } + else { return ((T) getAdditionalProperties().get(name)); } } @@ -197,26 +210,30 @@ public PaymentMethod with(String name, Object value) { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(PaymentMethod.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('['); + sb.append(PaymentMethod.class.getName()) + .append('@') + .append(Integer.toHexString(System.identityHashCode(this))) + .append('['); sb.append("id"); sb.append('='); - sb.append(((this.id == null)?"":this.id)); + sb.append(((this.id == null) ? "" : this.id)); sb.append(','); sb.append("type"); sb.append('='); - sb.append(((this.type == null)?"":this.type)); + sb.append(((this.type == null) ? "" : this.type)); sb.append(','); sb.append("cardNumber"); sb.append('='); - sb.append(((this.cardNumber == null)?"":this.cardNumber)); + sb.append(((this.cardNumber == null) ? "" : this.cardNumber)); sb.append(','); sb.append("additionalProperties"); sb.append('='); - sb.append(((this.additionalProperties == null)?"":this.additionalProperties)); + sb.append(((this.additionalProperties == null) ? "" : this.additionalProperties)); sb.append(','); - if (sb.charAt((sb.length()- 1)) == ',') { - sb.setCharAt((sb.length()- 1), ']'); - } else { + if (sb.charAt((sb.length() - 1)) == ',') { + sb.setCharAt((sb.length() - 1), ']'); + } + else { sb.append(']'); } return sb.toString(); @@ -225,10 +242,10 @@ public String toString() { @Override public int hashCode() { int result = 1; - result = ((result* 31)+((this.id == null)? 0 :this.id.hashCode())); - result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode())); - result = ((result* 31)+((this.type == null)? 0 :this.type.hashCode())); - result = ((result* 31)+((this.cardNumber == null)? 0 :this.cardNumber.hashCode())); + result = ((result * 31) + ((this.id == null) ? 0 : this.id.hashCode())); + result = ((result * 31) + ((this.additionalProperties == null) ? 0 : this.additionalProperties.hashCode())); + result = ((result * 31) + ((this.type == null) ? 0 : this.type.hashCode())); + result = ((result * 31) + ((this.cardNumber == null) ? 0 : this.cardNumber.hashCode())); return result; } @@ -241,7 +258,12 @@ public boolean equals(Object other) { return false; } PaymentMethod rhs = ((PaymentMethod) other); - return (((((this.id == rhs.id)||((this.id!= null)&&this.id.equals(rhs.id)))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties))))&&((this.type == rhs.type)||((this.type!= null)&&this.type.equals(rhs.type))))&&((this.cardNumber == rhs.cardNumber)||((this.cardNumber!= null)&&this.cardNumber.equals(rhs.cardNumber)))); + return (((((this.id == rhs.id) || ((this.id != null) && this.id.equals(rhs.id))) + && ((this.additionalProperties == rhs.additionalProperties) || ((this.additionalProperties != null) + && this.additionalProperties.equals(rhs.additionalProperties)))) + && ((this.type == rhs.type) || ((this.type != null) && this.type.equals(rhs.type)))) + && ((this.cardNumber == rhs.cardNumber) + || ((this.cardNumber != null) && this.cardNumber.equals(rhs.cardNumber)))); } } diff --git a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethodType.java b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethodType.java index 18c4e03..1cbfa50 100644 --- a/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethodType.java +++ b/src/test/java/io/zenwave360/modulith/events/scs/dtos/json/PaymentMethodType.java @@ -9,13 +9,14 @@ public enum PaymentMethodType { - VISA("VISA"), - MASTERCARD("MASTERCARD"); + VISA("VISA"), MASTERCARD("MASTERCARD"); + private final String value; + private final static Map CONSTANTS = new HashMap(); static { - for (PaymentMethodType c: values()) { + for (PaymentMethodType c : values()) { CONSTANTS.put(c.value, c); } } @@ -39,7 +40,8 @@ public static PaymentMethodType fromValue(String value) { PaymentMethodType constant = CONSTANTS.get(value); if (constant == null) { throw new IllegalArgumentException(value); - } else { + } + else { return constant; } }