diff --git a/src/test/java/com/fasterxml/jackson/dataformat/avro/failing/SerializeGeneratedTest.java b/src/test/java/com/fasterxml/jackson/dataformat/avro/failing/SerializeGeneratedTest.java new file mode 100644 index 0000000..13d6f29 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/avro/failing/SerializeGeneratedTest.java @@ -0,0 +1,24 @@ +package com.fasterxml.jackson.dataformat.avro.failing; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.dataformat.avro.AvroMapper; +import com.fasterxml.jackson.dataformat.avro.AvroSchema; +import com.fasterxml.jackson.dataformat.avro.AvroTestBase; +import com.fasterxml.jackson.dataformat.avro.gen.Event35; +import com.fasterxml.jackson.dataformat.avro.gen.Event35Id; + +// Test(s) for [dataformat-avro#35] +public class SerializeGeneratedTest extends AvroTestBase +{ + public void testWriteGeneratedEvent() throws Exception + { + Event35 event = new Event35(); + event.setPlayerCount(100); + Event35Id id = new Event35Id(); + id.setFirst(10); + ObjectMapper mapper = new AvroMapper(); + byte[] bytes = mapper.writer(new AvroSchema(Event35.SCHEMA$)).writeValueAsBytes(event); + assertNotNull(bytes); + } +} diff --git a/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35.java b/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35.java new file mode 100644 index 0000000..38d2e30 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35.java @@ -0,0 +1,187 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.fasterxml.jackson.dataformat.avro.gen; + +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public class Event35 extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Event\",\"namespace\":\"com.demonstration\",\"fields\":[{\"name\":\"playerCount\",\"type\":[\"null\",\"int\"]},{\"name\":\"eventID\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"EventID\",\"fields\":[{\"name\":\"description\",\"type\":[\"null\",{\"type\":\"string\",\"avro.java.string\":\"String\"}],\"default\":null},{\"name\":\"first\",\"type\":[\"null\",\"int\"],\"default\":null},{\"name\":\"second\",\"type\":[\"null\",\"int\"],\"default\":null}]}]}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + private java.lang.Integer playerCount; + private Event35Id eventID; + + /** + * Default constructor. + */ + public Event35() {} + + /** + * All-args constructor. + */ + public Event35(java.lang.Integer playerCount, Event35Id eventID) { + this.playerCount = playerCount; + this.eventID = eventID; + } + + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return playerCount; + case 1: return eventID; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: playerCount = (java.lang.Integer)value$; break; + case 1: eventID = (Event35Id)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'playerCount' field. + */ + public java.lang.Integer getPlayerCount() { + return playerCount; + } + + /** + * Sets the value of the 'playerCount' field. + * @param value the value to set. + */ + public void setPlayerCount(java.lang.Integer value) { + this.playerCount = value; + } + + /** + * Gets the value of the 'eventID' field. + */ + public Event35Id getEventID() { + return eventID; + } + + /** + * Sets the value of the 'eventID' field. + * @param value the value to set. + */ + public void setEventID(Event35Id value) { + this.eventID = value; + } + + /** Creates a new Event RecordBuilder */ + public static Event35.Builder newBuilder() { + return new Event35.Builder(); + } + + /** Creates a new Event RecordBuilder by copying an existing Builder */ + public static Event35.Builder newBuilder(Event35.Builder other) { + return new Event35.Builder(other); + } + + /** Creates a new Event RecordBuilder by copying an existing Event instance */ + public static Event35.Builder newBuilder(Event35 other) { + return new Event35.Builder(other); + } + + /** + * RecordBuilder for Event instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.Integer playerCount; + private Event35Id eventID; + + /** Creates a new Builder */ + private Builder() { + super(Event35.SCHEMA$); + } + + /** Creates a Builder by copying an existing Builder */ + private Builder(Event35.Builder other) { + super(other); + } + + /** Creates a Builder by copying an existing Event instance */ + private Builder(Event35 other) { + super(Event35.SCHEMA$); + if (isValidValue(fields()[0], other.playerCount)) { + this.playerCount = data().deepCopy(fields()[0].schema(), other.playerCount); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.eventID)) { + this.eventID = data().deepCopy(fields()[1].schema(), other.eventID); + fieldSetFlags()[1] = true; + } + } + + /** Gets the value of the 'playerCount' field */ + public java.lang.Integer getPlayerCount() { + return playerCount; + } + + /** Sets the value of the 'playerCount' field */ + public Event35.Builder setPlayerCount(java.lang.Integer value) { + validate(fields()[0], value); + this.playerCount = value; + fieldSetFlags()[0] = true; + return this; + } + + /** Checks whether the 'playerCount' field has been set */ + public boolean hasPlayerCount() { + return fieldSetFlags()[0]; + } + + /** Clears the value of the 'playerCount' field */ + public Event35.Builder clearPlayerCount() { + playerCount = null; + fieldSetFlags()[0] = false; + return this; + } + + /** Gets the value of the 'eventID' field */ + public Event35Id getEventID() { + return eventID; + } + + /** Sets the value of the 'eventID' field */ + public Event35.Builder setEventID(Event35Id value) { + validate(fields()[1], value); + this.eventID = value; + fieldSetFlags()[1] = true; + return this; + } + + /** Checks whether the 'eventID' field has been set */ + public boolean hasEventID() { + return fieldSetFlags()[1]; + } + + /** Clears the value of the 'eventID' field */ + public Event35.Builder clearEventID() { + eventID = null; + fieldSetFlags()[1] = false; + return this; + } + + @Override + public Event35 build() { + try { + Event35 record = new Event35(); + record.playerCount = fieldSetFlags()[0] ? this.playerCount : (java.lang.Integer) defaultValue(fields()[0]); + record.eventID = fieldSetFlags()[1] ? this.eventID : (Event35Id) defaultValue(fields()[1]); + return record; + } catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } +} diff --git a/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35Id.java b/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35Id.java new file mode 100644 index 0000000..22e0886 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35Id.java @@ -0,0 +1,236 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.fasterxml.jackson.dataformat.avro.gen; +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public class Event35Id extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"EventID\",\"namespace\":\"com.demonstration\",\"fields\":[{\"name\":\"description\",\"type\":[\"null\",{\"type\":\"string\",\"avro.java.string\":\"String\"}],\"default\":null},{\"name\":\"first\",\"type\":[\"null\",\"int\"],\"default\":null},{\"name\":\"second\",\"type\":[\"null\",\"int\"],\"default\":null}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + private java.lang.String description; + private java.lang.Integer first; + private java.lang.Integer second; + + /** + * Default constructor. + */ + public Event35Id() {} + + /** + * All-args constructor. + */ + public Event35Id(java.lang.String description, java.lang.Integer first, java.lang.Integer second) { + this.description = description; + this.first = first; + this.second = second; + } + + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return description; + case 1: return first; + case 2: return second; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: description = (java.lang.String)value$; break; + case 1: first = (java.lang.Integer)value$; break; + case 2: second = (java.lang.Integer)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'description' field. + */ + public java.lang.String getDescription() { + return description; + } + + /** + * Sets the value of the 'description' field. + * @param value the value to set. + */ + public void setDescription(java.lang.String value) { + this.description = value; + } + + /** + * Gets the value of the 'first' field. + */ + public java.lang.Integer getFirst() { + return first; + } + + /** + * Sets the value of the 'first' field. + * @param value the value to set. + */ + public void setFirst(java.lang.Integer value) { + this.first = value; + } + + /** + * Gets the value of the 'second' field. + */ + public java.lang.Integer getSecond() { + return second; + } + + /** + * Sets the value of the 'second' field. + * @param value the value to set. + */ + public void setSecond(java.lang.Integer value) { + this.second = value; + } + + /** Creates a new EventID RecordBuilder */ + public static Event35Id.Builder newBuilder() { + return new Event35Id.Builder(); + } + + /** Creates a new EventID RecordBuilder by copying an existing Builder */ + public static Event35Id.Builder newBuilder(Event35Id.Builder other) { + return new Event35Id.Builder(other); + } + + /** Creates a new EventID RecordBuilder by copying an existing EventID instance */ + public static Event35Id.Builder newBuilder(Event35Id other) { + return new Event35Id.Builder(other); + } + + /** + * RecordBuilder for EventID instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.String description; + private java.lang.Integer first; + private java.lang.Integer second; + + /** Creates a new Builder */ + private Builder() { + super(Event35Id.SCHEMA$); + } + + /** Creates a Builder by copying an existing Builder */ + private Builder(Event35Id.Builder other) { + super(other); + } + + /** Creates a Builder by copying an existing EventID instance */ + private Builder(Event35Id other) { + super(Event35Id.SCHEMA$); + if (isValidValue(fields()[0], other.description)) { + this.description = data().deepCopy(fields()[0].schema(), other.description); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.first)) { + this.first = data().deepCopy(fields()[1].schema(), other.first); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.second)) { + this.second = data().deepCopy(fields()[2].schema(), other.second); + fieldSetFlags()[2] = true; + } + } + + /** Gets the value of the 'description' field */ + public java.lang.String getDescription() { + return description; + } + + /** Sets the value of the 'description' field */ + public Event35Id.Builder setDescription(java.lang.String value) { + validate(fields()[0], value); + this.description = value; + fieldSetFlags()[0] = true; + return this; + } + + /** Checks whether the 'description' field has been set */ + public boolean hasDescription() { + return fieldSetFlags()[0]; + } + + /** Clears the value of the 'description' field */ + public Event35Id.Builder clearDescription() { + description = null; + fieldSetFlags()[0] = false; + return this; + } + + /** Gets the value of the 'first' field */ + public java.lang.Integer getFirst() { + return first; + } + + /** Sets the value of the 'first' field */ + public Event35Id.Builder setFirst(java.lang.Integer value) { + validate(fields()[1], value); + this.first = value; + fieldSetFlags()[1] = true; + return this; + } + + /** Checks whether the 'first' field has been set */ + public boolean hasFirst() { + return fieldSetFlags()[1]; + } + + /** Clears the value of the 'first' field */ + public Event35Id.Builder clearFirst() { + first = null; + fieldSetFlags()[1] = false; + return this; + } + + /** Gets the value of the 'second' field */ + public java.lang.Integer getSecond() { + return second; + } + + /** Sets the value of the 'second' field */ + public Event35Id.Builder setSecond(java.lang.Integer value) { + validate(fields()[2], value); + this.second = value; + fieldSetFlags()[2] = true; + return this; + } + + /** Checks whether the 'second' field has been set */ + public boolean hasSecond() { + return fieldSetFlags()[2]; + } + + /** Clears the value of the 'second' field */ + public Event35Id.Builder clearSecond() { + second = null; + fieldSetFlags()[2] = false; + return this; + } + + @Override + public Event35Id build() { + try { + Event35Id record = new Event35Id(); + record.description = fieldSetFlags()[0] ? this.description : (java.lang.String) defaultValue(fields()[0]); + record.first = fieldSetFlags()[1] ? this.first : (java.lang.Integer) defaultValue(fields()[1]); + record.second = fieldSetFlags()[2] ? this.second : (java.lang.Integer) defaultValue(fields()[2]); + return record; + } catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } +} diff --git a/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35Log.java b/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35Log.java new file mode 100644 index 0000000..624e392 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/avro/gen/Event35Log.java @@ -0,0 +1,286 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.fasterxml.jackson.dataformat.avro.gen; +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public class Event35Log extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"EventLog\",\"namespace\":\"com.demonstration\",\"fields\":[{\"name\":\"version\",\"type\":[\"null\",\"int\"],\"default\":null},{\"name\":\"MAX_EVENTS\",\"type\":[\"null\",\"int\"],\"default\":null},{\"name\":\"eventCount\",\"type\":[\"null\",{\"type\":\"int\",\"java-class\":\"java.lang.Byte\"}],\"default\":null},{\"name\":\"events\",\"type\":[\"null\",{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Event\",\"fields\":[{\"name\":\"playerCount\",\"type\":[\"null\",\"int\"]},{\"name\":\"eventID\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"EventID\",\"fields\":[{\"name\":\"description\",\"type\":[\"null\",{\"type\":\"string\",\"avro.java.string\":\"String\"}],\"default\":null},{\"name\":\"first\",\"type\":[\"null\",\"int\"],\"default\":null},{\"name\":\"second\",\"type\":[\"null\",\"int\"],\"default\":null}]}]}]},\"java-class\":\"java.util.List\"}],\"default\":null}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + private java.lang.Integer version; + private java.lang.Integer MAX_EVENTS; + private java.lang.Integer eventCount; + private java.util.List events; + + /** + * Default constructor. + */ + public Event35Log() {} + + /** + * All-args constructor. + */ + public Event35Log(java.lang.Integer version, java.lang.Integer MAX_EVENTS, java.lang.Integer eventCount, java.util.List events) { + this.version = version; + this.MAX_EVENTS = MAX_EVENTS; + this.eventCount = eventCount; + this.events = events; + } + + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return version; + case 1: return MAX_EVENTS; + case 2: return eventCount; + case 3: return events; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: version = (java.lang.Integer)value$; break; + case 1: MAX_EVENTS = (java.lang.Integer)value$; break; + case 2: eventCount = (java.lang.Integer)value$; break; + case 3: events = (java.util.List)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'version' field. + */ + public java.lang.Integer getVersion() { + return version; + } + + /** + * Sets the value of the 'version' field. + * @param value the value to set. + */ + public void setVersion(java.lang.Integer value) { + this.version = value; + } + + /** + * Gets the value of the 'MAX_EVENTS' field. + */ + public java.lang.Integer getMAXEVENTS() { + return MAX_EVENTS; + } + + /** + * Sets the value of the 'MAX_EVENTS' field. + * @param value the value to set. + */ + public void setMAXEVENTS(java.lang.Integer value) { + this.MAX_EVENTS = value; + } + + /** + * Gets the value of the 'eventCount' field. + */ + public java.lang.Integer getEventCount() { + return eventCount; + } + + /** + * Sets the value of the 'eventCount' field. + * @param value the value to set. + */ + public void setEventCount(java.lang.Integer value) { + this.eventCount = value; + } + + /** + * Gets the value of the 'events' field. + */ + public java.util.List getEvents() { + return events; + } + + /** + * Sets the value of the 'events' field. + * @param value the value to set. + */ + public void setEvents(java.util.List value) { + this.events = value; + } + + /** Creates a new EventLog RecordBuilder */ + public static Event35Log.Builder newBuilder() { + return new Event35Log.Builder(); + } + + /** Creates a new EventLog RecordBuilder by copying an existing Builder */ + public static Event35Log.Builder newBuilder(Event35Log.Builder other) { + return new Event35Log.Builder(other); + } + + /** Creates a new EventLog RecordBuilder by copying an existing EventLog instance */ + public static Event35Log.Builder newBuilder(Event35Log other) { + return new Event35Log.Builder(other); + } + + /** + * RecordBuilder for EventLog instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.Integer version; + private java.lang.Integer MAX_EVENTS; + private java.lang.Integer eventCount; + private java.util.List events; + + /** Creates a new Builder */ + private Builder() { + super(Event35Log.SCHEMA$); + } + + /** Creates a Builder by copying an existing Builder */ + private Builder(Event35Log.Builder other) { + super(other); + } + + /** Creates a Builder by copying an existing EventLog instance */ + private Builder(Event35Log other) { + super(Event35Log.SCHEMA$); + if (isValidValue(fields()[0], other.version)) { + this.version = data().deepCopy(fields()[0].schema(), other.version); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.MAX_EVENTS)) { + this.MAX_EVENTS = data().deepCopy(fields()[1].schema(), other.MAX_EVENTS); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.eventCount)) { + this.eventCount = data().deepCopy(fields()[2].schema(), other.eventCount); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.events)) { + this.events = data().deepCopy(fields()[3].schema(), other.events); + fieldSetFlags()[3] = true; + } + } + + /** Gets the value of the 'version' field */ + public java.lang.Integer getVersion() { + return version; + } + + /** Sets the value of the 'version' field */ + public Event35Log.Builder setVersion(java.lang.Integer value) { + validate(fields()[0], value); + this.version = value; + fieldSetFlags()[0] = true; + return this; + } + + /** Checks whether the 'version' field has been set */ + public boolean hasVersion() { + return fieldSetFlags()[0]; + } + + /** Clears the value of the 'version' field */ + public Event35Log.Builder clearVersion() { + version = null; + fieldSetFlags()[0] = false; + return this; + } + + /** Gets the value of the 'MAX_EVENTS' field */ + public java.lang.Integer getMAXEVENTS() { + return MAX_EVENTS; + } + + /** Sets the value of the 'MAX_EVENTS' field */ + public Event35Log.Builder setMAXEVENTS(java.lang.Integer value) { + validate(fields()[1], value); + this.MAX_EVENTS = value; + fieldSetFlags()[1] = true; + return this; + } + + /** Checks whether the 'MAX_EVENTS' field has been set */ + public boolean hasMAXEVENTS() { + return fieldSetFlags()[1]; + } + + /** Clears the value of the 'MAX_EVENTS' field */ + public Event35Log.Builder clearMAXEVENTS() { + MAX_EVENTS = null; + fieldSetFlags()[1] = false; + return this; + } + + /** Gets the value of the 'eventCount' field */ + public java.lang.Integer getEventCount() { + return eventCount; + } + + /** Sets the value of the 'eventCount' field */ + public Event35Log.Builder setEventCount(java.lang.Integer value) { + validate(fields()[2], value); + this.eventCount = value; + fieldSetFlags()[2] = true; + return this; + } + + /** Checks whether the 'eventCount' field has been set */ + public boolean hasEventCount() { + return fieldSetFlags()[2]; + } + + /** Clears the value of the 'eventCount' field */ + public Event35Log.Builder clearEventCount() { + eventCount = null; + fieldSetFlags()[2] = false; + return this; + } + + /** Gets the value of the 'events' field */ + public java.util.List getEvents() { + return events; + } + + /** Sets the value of the 'events' field */ + public Event35Log.Builder setEvents(java.util.List value) { + validate(fields()[3], value); + this.events = value; + fieldSetFlags()[3] = true; + return this; + } + + /** Checks whether the 'events' field has been set */ + public boolean hasEvents() { + return fieldSetFlags()[3]; + } + + /** Clears the value of the 'events' field */ + public Event35Log.Builder clearEvents() { + events = null; + fieldSetFlags()[3] = false; + return this; + } + + @Override + public Event35Log build() { + try { + Event35Log record = new Event35Log(); + record.version = fieldSetFlags()[0] ? this.version : (java.lang.Integer) defaultValue(fields()[0]); + record.MAX_EVENTS = fieldSetFlags()[1] ? this.MAX_EVENTS : (java.lang.Integer) defaultValue(fields()[1]); + record.eventCount = fieldSetFlags()[2] ? this.eventCount : (java.lang.Integer) defaultValue(fields()[2]); + record.events = fieldSetFlags()[3] ? this.events : (java.util.List) defaultValue(fields()[3]); + return record; + } catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } +}