Re: [Simple-support] De-serialization problem -- valid reference not valid?
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2009-02-17 23:33:15
|
Hi,
Thanks, ill take a look.
Niall
--- On Tue, 2/17/09, Alan Deikman <Ala...@zn...> wrote:
> From: Alan Deikman <Ala...@zn...>
> Subject: Re: [Simple-support] De-serialization problem -- valid reference not valid?
> To: sim...@li...
> Date: Tuesday, February 17, 2009, 3:10 PM
> Niall Gallagher wrote:
> > Is this easy to reproduce? Would it be possible to
> write a test case to expose this problem, at least then I
> could fix the issue from a known reproducable test.
> >
>
> OK, I think I have test case for you in the attached file.
> The program run without a command-line parameter will write
> the file "SimpleBug.xml". If you run it with the
> command line parameter "-r" it will try to read
> that file, with the exception. The exception I got was:
>
> org.simpleframework.xml.graph.CycleException: Invalid
> reference '4' found
>
> The file it should generate (but can't read) looks like
> this:
>
> <simpleBug id="0">
> <test1 id="1">
> <data id="2">
> <entry>
> <string
> id="3">key1</string>
> <object class="java.lang.String"
> id="4">value</object>
> </entry>
> </data>
> </test1>
> <test2 id="5">
> <data id="6">
> <entry>
> <string
> id="7">key2</string>
> <object class="java.lang.String"
> ref="4"/>
> </entry>
> </data>
> </test2>
> </simpleBug>
>
> Thanks again for this great class library.
>
> -- Alan Deikman
> ZNYX Networks
>
> /*
> * SimpleBug.java
> *
> */
>
> package com.test.teststuff;
>
> import java.io.File;
> import java.util.TreeMap;
> import org.simpleframework.xml.Element;
> import org.simpleframework.xml.ElementMap;
> import org.simpleframework.xml.Root;
> import org.simpleframework.xml.Serializer;
> import org.simpleframework.xml.core.Persister;
> import org.simpleframework.xml.core.Strategy;
> import org.simpleframework.xml.graph.CycleStrategy;
>
> /**
> *
> * @author Alan Deikman
> */
> @Root public class SimpleBug {
>
> @Element protected Mojo test1;
> @Element protected Mojo test2;
>
> public SimpleBug() {
> test1 = new Mojo();
> test1.data.put("key1",
> "value");
> test2 = new Mojo();
> test2.data.put("key2",
> "value");
> }
>
> /**
> * @param args the command line arguments
> */
> public static void main(String[] args) {
>
> SimpleBug bug = null;
>
> boolean write = true;
> if (args.length > 0 &&
> args[0].equals("-r")) write = false;
>
> Strategy resolver = new
> CycleStrategy("id", "ref");
> Serializer s = new Persister(resolver);
> File file = new File("SimpleBug.xml");
>
> if (write) {
> bug = new SimpleBug();
> try {
> s.write(bug, file);
> } catch (Exception ex) {
> System.out.println("Something went
> wrong.");
> }
> }
>
> else {
> try {
> bug = s.read(SimpleBug.class, file);
> } catch (Exception ex) {
> System.out.println("Can't
> parse");
> System.out.println(ex.toString());
> }
> }
> }
>
> public static class Mojo {
> @ElementMap protected TreeMap<String, Object>
> data;
> public Mojo() {
> data = new TreeMap<String, Object>();
> }
> }
>
> }
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009,
> San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open
> Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open
> source participation
> -Receive a $600 discount off the registration fee with the
> source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H_______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|