You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Sharad Agarwal (JIRA)" <ji...@apache.org> on 2009/07/15 06:15:15 UTC
[jira] Commented: (AVRO-78) 'reflect' implementation works only
with public fields
[ https://issues.apache.org/jira/browse/AVRO-78?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12731261#action_12731261 ]
Sharad Agarwal commented on AVRO-78:
------------------------------------
Testcase:
{code}
class TestReflect {
....
@Test
public void testRefRecord() throws IOException {
Schema schm = ReflectData.getSchema(RefRecord.class);
Class<?> clazz = RefRecord.class;
String prefix =
((clazz.getEnclosingClass() == null
|| "null".equals(clazz.getEnclosingClass())) ?
clazz.getPackage().getName() + "."
: (clazz.getEnclosingClass().getName() + "$"));
ReflectDatumWriter writer = new ReflectDatumWriter(schm);
ByteArrayOutputStream out = new ByteArrayOutputStream();
RefRecord rec = new RefRecord();
rec.x = 5;
rec.y = 10;
writer.write(rec, new BinaryEncoder(out));
ReflectDatumReader reader = new ReflectDatumReader(schm, prefix);
Object decoded =
reader.read(null, new BinaryDecoder(
new ByteArrayInputStream(out.toByteArray())));
assertEquals(rec, decoded);
}
public static class RefRecord {
public int x = 1;
private int y = 2;
public int hashCode() {
return x + y;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final RefRecord other = (RefRecord) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
}
{code}
> 'reflect' implementation works only with public fields
> ------------------------------------------------------
>
> Key: AVRO-78
> URL: https://issues.apache.org/jira/browse/AVRO-78
> Project: Avro
> Issue Type: Bug
> Components: java
> Reporter: Sharad Agarwal
>
> As per the documentation 'reflect' implementation should work for Class#getDeclaredFields()
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.