Re: [Simple-support] Persister write exception
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-08-10 12:02:57
|
Hi, If you still have an issue can you demonstrate the problem in a JUnit TestCase. If there is an issue I will make sure to include the fix in the next release. Thanks, Niall --- On Tue, 9/8/11, Courtney, Phil <Phi...@sr...> wrote: From: Courtney, Phil <Phi...@sr...> Subject: RE: [Simple-support] Persister write exception To: "Niall Gallagher" <gal...@ya...>, sim...@li... Received: Tuesday, 9 August, 2011, 8:48 AM I suppose it could be a case issue. I am not really sure how the annotations work with Simple for reading and writing the xml document. An excerpt from the original xml document that was parsed correctly by Simple is below. ProviderInformation is camel case starting with a upper case letter. <spd:SolutionPackageDeployment name="A" … > … <spd:ProviderInformation> <spd:Manufacturer name="token" uuid="34d00b70-ba29-11e0-962b-0800200c9a66" /> </spd:ProviderInformation> …</spd:SolutionPackageDeployment> When parsed, Simple created an instance of a SolutionPackageDeploymentType which contains a ProviderInformation element as defined below: @Element(name = "ProviderInformation", required = true) protected ProviderInformationType providerInformation; As you can see, the name is defined in the annotation to match the case in the document, but the field name begins with a lower case letter. This is a naming convention that is used by JAXB. Since Simple does not have a compiler that will generate annotated classes from a schema, I used JAXB to generate the annotated class bindings (which we have used on our workstation and server applications), then wrote a Perl script to translate the JAXB annotations into Simple annotations for our new Android application. The naming works fine for parsing, but I get the exception when I attempt to create a document from the classes that were created by parsing the document. As a test case, I was just attempting to read a document into the annotated classes then write those classes back into a document and compare the output document with the original document. The exception seems to indicate that Element 'providerInformation' not defined in class com.sra.rtapp.spdd.SolutionPackageDeploymentType, but as you can see from the code excerpt above, it is a field in the SolutionPackageDeploymentType class. And it is parsed correctly from the original document. I tried changing the ProviderInformation element field name in the SolutionPackageDeploymentType to begin with an upper case letter as shown below: @Element(name = "ProviderInformation", required = true) protected ProviderInformationType ProviderInformation; The document still parsed correctly, and using a debugger the field name in the SolutionPackageDeploymentType instance was ProviderInformation as expected. However, I still got exactly the same error: Element 'providerInformation' not defined in class … Note the lower case beginning letter. As a final test case I tried changing the element name in the document and in the SolutionPackageDeploymentType to begin with a lower case letter – i.e. @Element(name = "providerInformation", required = true) protected ProviderInformationType providerInformation; Again, the document parsed correctly. But this time Simple was able to write the element. So it appears that Simple can correctly parse elements that begin with either case (as specified in the annotation), but can only write elements that begin with a lower case letter. Sorry for the lengthy email, but I hope this adequately describes the symptoms. Phil From: Niall Gallagher [mailto:gal...@ya...] Sent: Tuesday, August 09, 2011 3:52 AM To: sim...@li...; Courtney, Phil Subject: RE: [Simple-support] Persister write exception Are you sure this is not a case sensitivity error? Does the case of the element match? XML is case sensitive. --- On Mon, 8/8/11, Courtney, Phil <Phi...@sr...> wrote: From: Courtney, Phil <Phi...@sr...> Subject: RE: [Simple-support] Persister write exception To: "Niall Gallagher" <gal...@ya...>, sim...@li... Received: Monday, 8 August, 2011, 12:52 PMI have removed the previous email content to avoid exceeding the maximum email length. The stack trace is below: org.simpleframework.xml.core.ElementException: Element 'providerInformation' not defined in class com.sra.rtapp.spdd.SolutionPackageDeploymentType at org.simpleframework.xml.core.Composite.writeElements(Composite.java:1146) at org.simpleframework.xml.core.Composite.writeSection(Composite.java:1056) at org.simpleframework.xml.core.Composite.write(Composite.java:1026) at org.simpleframework.xml.core.Composite.write(Composite.java:1003) at org.simpleframework.xml.core.Traverser.write(Traverser.java:236) at org.simpleframework.xml.core.Traverser.write(Traverser.java:208) at org.simpleframework.xml.core.Traverser.write(Traverser.java:186) at org.simpleframework.xml.core.Persister.write(Persister.java:1187) at org.simpleframework.xml.core.Persister.write(Persister.java:1169) at org.simpleframework.xml.core.Persister.write(Persister.java:1147) at org.simpleframework.xml.core.Persister.write(Persister.java:1266) at com.sra.rtapp.spdd.SolutionPackageDeploymentDescriptor.toString(SolutionPackageDeploymentDescriptor.java:78) at com.sra.rtapp.solutionpackage.SolutionPackageDeploymentActivity.onCreate(SolutionPackageDeploymentActivity.java:34) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) at android.app.ActivityThread.access$1500(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) I am running on Android 2.3.3. Phil |