RuntimeException when building an annoted schema for inner classes
GoogleCodeExporter opened this issue · comments
What steps will reproduce the problem?
1. Create an inner class with an annotated field
2. Call RuntimeSchema.createSchema on this class.
What is the expected output? What do you see instead?
java.lang.RuntimeException: When using annotation-based mapping, all fields
must be annotated with @Tag
at com.dyuproject.protostuff.runtime.RuntimeSchema.createFrom(RuntimeSchema.java:209)
at com.dyuproject.protostuff.runtime.RuntimeSchema.createFrom(RuntimeSchema.java:156)
at com.dyuproject.protostuff.runtime.DefaultIdStrategy$Lazy.getSchema(DefaultIdStrategy.java:620)
at com.dyuproject.protostuff.runtime.RuntimeSchema.getSchema(RuntimeSchema.java:119)
at com.dyuproject.protostuff.runtime.RuntimeSchema.getSchema(RuntimeSchema.java:111)
What version of the product are you using? On what operating system?
Version 1.0.7 on Windows
Please provide any additional information below.
The field with no Tag is the field this$0 created by java because the class is
an inner class. I guess this kind of field should be filtered out.
Original issue reported on code.google.com by idispatc...@gmail.com
on 25 Aug 2013 at 1:44
If that field is filtered out, that field will be null on deser which will not
be correct since the instance needs that field.
Since you have control of the source, you can either:
1. Mark the class as static and provide the parent instance in the constructor
and assign to a field that you can annotate.
2. Avoid annotation for inner classes.
Original comment by david.yu...@gmail.com
on 26 Aug 2013 at 3:10
Yes, you're right about the field being needed.
Perhaps you can add your comment about this particular case in the
documentation or provide a more specialized error message: unless you are
intimate with java inner workings you can't imagine why such an exception
occurs.
Original comment by idispatc...@gmail.com
on 26 Aug 2013 at 3:31
Just finished documenting this on the ProtostuffRuntime wiki.
Thanks for reporting.
Original comment by david.yu...@gmail.com
on 26 Aug 2013 at 4:04