Skip to content

Commit

Permalink
AVRO-2386: Make customEncode and customDecode public (#511)
Browse files Browse the repository at this point in the history
* Make customEncode and customDecode methods public

* Make methods in superclass public

(cherry picked from commit e250dcc)
  • Loading branch information
scatrin authored and Fokko committed May 7, 2019
1 parent 16de62a commit 3c76495
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ protected boolean hasCustomCoders() {
return false;
}

protected void customEncode(Encoder out) throws IOException {
public void customEncode(Encoder out) throws IOException {
throw new UnsupportedOperationException();
}

protected void customDecode(ResolvingDecoder in) throws IOException {
public void customDecode(ResolvingDecoder in) throws IOException {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static {
#if ($this.isCustomCodable($schema))
@Override protected boolean hasCustomCoders() { return true; }

@Override protected void customEncode(org.apache.avro.io.Encoder out)
@Override public void customEncode(org.apache.avro.io.Encoder out)
throws java.io.IOException
{
#set ($nv = 0)## Counter to ensure unique var-names
Expand All @@ -550,7 +550,7 @@ static {
#end
}

@Override protected void customDecode(org.apache.avro.io.ResolvingDecoder in)
@Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
throws java.io.IOException
{
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.avro.codegentest;

import org.apache.avro.codegentest.other.NestedOtherNamespaceRecord;
import org.apache.avro.codegentest.some.NestedSomeNamespaceRecord;
import org.junit.Test;

public class TestNestedRecordsWithDifferentNamespaces extends AbstractSpecificRecordTest {

@Test
public void testNestedRecordsWithDifferentNamespaces() {
NestedSomeNamespaceRecord instanceOfGeneratedClass = NestedSomeNamespaceRecord.newBuilder()
.setNestedRecordBuilder(NestedOtherNamespaceRecord.newBuilder().setSomeField(1)).build();
verifySerDeAndStandardMethods(instanceOfGeneratedClass);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{"namespace": "org.apache.avro.codegentest.some",
"type": "record",
"name": "NestedSomeNamespaceRecord",
"doc" : "Test nested types with different namespace than the outer type",
"fields": [
{
"name": "nestedRecord",
"type": {
"namespace": "org.apache.avro.codegentest.other",
"type": "record",
"name": "NestedOtherNamespaceRecord",
"fields": [
{
"name": "someField",
"type": "int"
}
]
}
}]
}



Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public Player build() {

@Override protected boolean hasCustomCoders() { return true; }

@Override protected void customEncode(org.apache.avro.io.Encoder out)
@Override public void customEncode(org.apache.avro.io.Encoder out)
throws java.io.IOException
{
out.writeInt(this.number);
Expand All @@ -517,7 +517,7 @@ public Player build() {

}

@Override protected void customDecode(org.apache.avro.io.ResolvingDecoder in)
@Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
throws java.io.IOException
{
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
Expand Down
4 changes: 2 additions & 2 deletions lang/java/tools/src/test/compiler/output/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public Player build() {

@Override protected boolean hasCustomCoders() { return true; }

@Override protected void customEncode(org.apache.avro.io.Encoder out)
@Override public void customEncode(org.apache.avro.io.Encoder out)
throws java.io.IOException
{
out.writeInt(this.number);
Expand All @@ -517,7 +517,7 @@ public Player build() {

}

@Override protected void customDecode(org.apache.avro.io.ResolvingDecoder in)
@Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
throws java.io.IOException
{
org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
Expand Down

0 comments on commit 3c76495

Please sign in to comment.