-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
avro/src/main/java/tools/jackson/dataformat/avro/schema/EnumVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
avro/src/test/java/tools/jackson/dataformat/avro/schema/EnumSchema422Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package tools.jackson.dataformat.avro.schema; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
import tools.jackson.databind.exc.InvalidDefinitionException; | ||
import tools.jackson.dataformat.avro.AvroMapper; | ||
import tools.jackson.dataformat.avro.AvroTestBase; | ||
|
||
// For [dataformats-binary#422] | ||
public class EnumSchema422Test extends AvroTestBase | ||
{ | ||
enum EnumType422 { | ||
CARD_S("CARD-S"); | ||
|
||
private final String value; | ||
|
||
EnumType422(String value) { | ||
this.value = value; | ||
} | ||
|
||
@JsonValue | ||
public String value() { | ||
return this.value; | ||
} | ||
} | ||
|
||
static class Wrapper422 { | ||
public EnumType422 contract; | ||
} | ||
|
||
private final AvroMapper MAPPER = newMapper(); | ||
|
||
// For [dataformats-binary#422] | ||
@Test | ||
public void testEnumSchemaGeneration422() throws Exception | ||
{ | ||
// First, failure due to invalid enum value (when generating as Enum) | ||
AvroSchemaGenerator gen = new AvroSchemaGenerator() | ||
.enableLogicalTypes(); | ||
try { | ||
MAPPER.acceptJsonFormatVisitor(Wrapper422.class, gen); | ||
fail("Expected failure"); | ||
} catch (InvalidDefinitionException e) { // in 2.x | ||
verifyException(e, "Problem generating Avro `Schema` for Enum type"); | ||
verifyException(e, "Illegal character in"); | ||
} | ||
|
||
// But then success when configuring to produce Strings for Enum types | ||
|
||
gen = new AvroSchemaGenerator() | ||
.enableLogicalTypes() | ||
.enableWriteEnumAsString(); | ||
MAPPER.acceptJsonFormatVisitor(Wrapper422.class, gen); | ||
|
||
org.apache.avro.Schema avroSchema = gen.getGeneratedSchema().getAvroSchema(); | ||
String avroSchemaInJSON = avroSchema.toString(true); | ||
assertNotNull(avroSchemaInJSON); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters