Tatu, thanks for your last response. Now for a new one. I use 
jackson whenever possible for my xml deserialization. Nothing faster for 
quick development. I go with an abstract class with a HashMap attribute to 
catch all the "unhandled attributes" with a @JsonAnySetter, then gradually 
add the specific attributes as I start to care about them.

One basic limitation is when the xml contains multiple children with the 
same element name. Jackson overwrites all but the last instance. So I add a 
custom handler in the @JsonAnySetter to populate this one field. Gets 
around most problems.

But this doesn't work recursively.

The xml I am parsing can be found at 
https://github.com/Esri/joint-military-symbology-xml/blob/dev/source/JointMilitarySymbologyLibraryCS/jmsml.config

The problem is that the <GraphicFolder> is recursive:

<GraphicFolder ...>
   <GraphicFolder ...>
     <GraphicFolder .../>
   </GraphicFolder>
</GraphicFolder>

and I am stumped. My java code is something like:

class GraphicFolder {
List<JmslGraphicFolder> graphicFolders = new ArrayList<JmslGraphicFolder>();

public JmslGraphicFolder(Object value) {
Map<String, Object> map = (Map<String, Object>) value;
Object child = map.get("GraphicFolder");
for (Object object : (List) child) {
graphicFolders.add(new JmslGraphicFolder(object));
}
}
@Override protected boolean handleSetter(String key, Object value) {
switch (key) {
case "GraphicFolder":
graphicFolders.add(new JmslGraphicFolder(value));
return true;
}
}
}

You can see in the handleSetter() method how we can handle multiple 
elements with the same name.
The problem is that the "Map<String, Object> map" object is outside my 
control. Jackson has already parsed it and eliminated the duplicates before 
I receive it.
So the trick works once but not recursively.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to