In this post we will serialize data using this schema:
and deserialize it using a different schema
which has following modifications:
- university_id field is removed.
- age field is added.
- result_score field is renamed to score.
- If a new field is added then it must have a default value. Also specify type as an array of types starting with null e.g. "type": ["null", "string"] otherwise you will get this error:
Exception in thread "main" java.lang.NoSuchMethodError: org.codehaus.jackson.node.ValueNode.asText()Ljava/lang/String;
- If a field is renamed then the old name must be present as aliases.
In the this java program we serialize data using StudentActivity.avsc schema and deserialize data using StudentActivityNew.avsc schema
On executing this code we see that Avro handles the modifications without any issues and our data is deserialized properly.