-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3244175
commit da74291
Showing
5 changed files
with
88 additions
and
11 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/com/fasterxml/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
60 changes: 60 additions & 0 deletions
60
avro/src/test/java/com/fasterxml/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,60 @@ | ||
package com.fasterxml.jackson.dataformat.avro.schema; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
import com.fasterxml.jackson.dataformat.avro.AvroMapper; | ||
import com.fasterxml.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 (IllegalArgumentException 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