-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
9 changed files
with
246 additions
and
84 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
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
48 changes: 48 additions & 0 deletions
48
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package tools.jackson.dataformat.avro.schema; | ||
|
||
import tools.jackson.databind.*; | ||
import tools.jackson.databind.introspect.AnnotatedClass; | ||
import tools.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor; | ||
|
||
import org.apache.avro.Schema; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Set; | ||
|
||
/** | ||
* Specific visitor for Java Enum types that are to be exposed as | ||
* Avro Enums. Used unless Java Enums are to be mapped to Avro Strings. | ||
*/ | ||
public class EnumVisitor extends JsonStringFormatVisitor.Base | ||
implements SchemaBuilder | ||
{ | ||
protected final SerializerProvider _provider; | ||
protected final JavaType _type; | ||
protected final DefinedSchemas _schemas; | ||
|
||
protected Set<String> _enums; | ||
|
||
public EnumVisitor(SerializerProvider provider, DefinedSchemas schemas, JavaType t) { | ||
_schemas = schemas; | ||
_type = t; | ||
_provider = provider; | ||
} | ||
|
||
@Override | ||
public void enumTypes(Set<String> enums) { | ||
_enums = enums; | ||
} | ||
|
||
@Override | ||
public Schema builtAvroSchema() { | ||
if (_enums == null) { | ||
throw new IllegalStateException("Possible enum values cannot be null"); | ||
} | ||
|
||
AnnotatedClass annotations = _provider.introspectClassAnnotations(_type); | ||
Schema s = AvroSchemaHelper.createEnumSchema(_provider.getConfig(), _type, | ||
annotations, new ArrayList<>(_enums)); | ||
_schemas.addSchema(_type, s); | ||
return s; | ||
} | ||
} |
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
Oops, something went wrong.