Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Fix #35
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 9, 2016
1 parent 3cb9da4 commit 85a67b8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ Peter Royal (osi@github)
- Contributed #27: Support serialization of `BigDecimal` values
(2.6.4)

Anand Shah (anandshah123@github)

- Reported #35: Not able to serialize avro generated object having schema$ object
(2.7.3)
5 changes: 5 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-dataformat-avro
= Releases
------------------------------------------------------------------------

2.7.3 (08-Mar-2016)

#35: Not able to serialize avro generated object having schema$ object
(reported by Anand S)

2.7.2 (27-Feb-2016)

- Change build to produce JDK6-compatible jar, to allow use on JDK6 runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public AvroModule()
{
super(PackageVersion.VERSION);
addSerializer(new SchemaSerializer());
// 08-Mar-2016, tatu: to fix [dataformat-avro#35], need to prune 'schema' property:
setSerializerModifier(new AvroSerializerModifier());
}

/**
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.fasterxml.jackson.dataformat.avro.failing;
package com.fasterxml.jackson.dataformat.avro;

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;

Expand Down

0 comments on commit 85a67b8

Please sign in to comment.