[Simple-support] Question regarding implementing my own strategy/converter
Brought to you by:
niallg
|
From: Jang-Soo L. <jan...@gm...> - 2011-12-02 05:35:49
|
Hello all, I just wanted to start by saying that using this framework has been really helpful so far. I'm trying to do something that might be somewhat non-standard. Here's the general idea: I want to deserialize XML into objects which all might have a certain subtype (not sub in terms of inheritance, but just as a separate class) as a field. An instance of that subtype would have information which would tell me where to get information from. The XML might look like many things, but they'd all potentially have one or more instances of a SubType within the hierarchy (some examples below). I'd have classes defined for each of these items, but I would like to shy away from writing multiple converters (Doesn't seem to have a good way to do this with one, but I might be mistaken), and my attempts at writing a custom Strategy are falling a bit flat. Part of it seems to be that when I write my own strategy and plug it into the Persister's constructor, the strategy's write code seems to be working as expected (can examine the object, look through the object via reflection for fields of type SubType and write XML I want to do), but the read code does not seem to work (Even though I've implemented Value and instantiate the innerValue via reflection and set the innerValue's properties, and then set the original Value's innerValue, it does not seem to stick). The read code is being run, I am sure of that [I see debug statements being hit], but it seems that whether I return null or an instantiated Value implementation from read, the Persister is choosing a different strategy [or does something else] to override the results of the custom strategy. Is there a good way to choose to override a default strategy? Alternatively, is there a better way to do this than writing multiple converters [without resorting to writing a converter for Object] and/or working with the strategy? I've also looked at Visitor, but I don't think that's what I want because I want to work with the object that's getting deserialized. Thanks in advance! <SomeObject> <SomeField class="SubType"> <URL>http://site/something.html</URL> </SomeField> </SomeObject> or it might look like <SomeObject> <SomeField class="SubType"> <URL>http://site/something.html</URL> </SomeField> <SomeField class="SubType"> <URL>http://site/something.html</URL> </SomeField> <SomeField class="SubType"> <URL>http://site/something.html</URL> </SomeField> </SomeObject> or it might look like <SomeItem> <SomeObject> <SomeField class="SubType"> <URL>http://site/something.html</URL> </SomeField> <SomeField class="SubType"> <URL>http://site/something.html</URL> </SomeField> <SomeField class="SubType"> <URL>http://site/something.html</URL> </SomeField> </SomeObject> </SomeItem> |