This repository has been archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
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
1 parent
3cb9da4
commit 85a67b8
Showing
5 changed files
with
56 additions
and
3 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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/fasterxml/jackson/dataformat/avro/AvroSerializerModifier.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,44 @@ | ||
package com.fasterxml.jackson.dataformat.avro; | ||
|
||
import java.util.*; | ||
|
||
import org.apache.avro.specific.SpecificRecordBase; | ||
import org.codehaus.jackson.map.BeanProperty; | ||
|
||
import com.fasterxml.jackson.databind.BeanDescription; | ||
import com.fasterxml.jackson.databind.SerializationConfig; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedClass; | ||
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; | ||
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; | ||
|
||
/** | ||
* Serializer modifier used to suppress serialization of "schema" | ||
* property for Avro-generated types. | ||
* | ||
* @since 2.7.2 | ||
*/ | ||
public class AvroSerializerModifier | ||
extends BeanSerializerModifier | ||
{ | ||
@Override | ||
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, | ||
BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) | ||
{ | ||
AnnotatedClass ac = beanDesc.getClassInfo(); | ||
// Couple of ways to determine if it's generated class: main alternative | ||
// would be to look for annotation `AvroGenerated` but check for base | ||
// class seems simpler and as robust: | ||
|
||
if (SpecificRecordBase.class.isAssignableFrom(ac.getRawType())) { | ||
Iterator<BeanPropertyWriter> it = beanProperties.iterator(); | ||
while (it.hasNext()) { | ||
BeanPropertyWriter prop = it.next(); | ||
if ("schema".equals(prop.getName())) { | ||
it.remove(); | ||
break; | ||
} | ||
} | ||
} | ||
return beanProperties; | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
.../avro/failing/SerializeGeneratedTest.java → ...taformat/avro/SerializeGeneratedTest.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