You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Maciek Kolesnik <mk...@gmail.com> on 2005/10/13 22:37:18 UTC

[betwixt] serialization suppression in betwixt

 Hi,
 I recently downloaded v0.7 of the betwixt. The tool does really a great job
- highly customizable and easy to use.
I do have a suggestion for a small improvement though:
As far as I know currently it is impossible to intercept the process of
descending into the object graph by a custom code.
Changing signature of these 2 methods

writeElement(...) (2 signatures)

to protected would give me ability to suppress the descent into children
when contextually my code determines that it does not need to go any deeper
(optimization measure). Any other similar scheme where execution of
writeElement(...) can be conditionally prevented could do a job too i think.

Here is how I would like to use it:
protected void writeElement(String namespaceUri, String localName, String
qualifiedName, ElementDescriptor elementDescriptor, Context context) throws
IOException, SAXException, IntrospectionException {

String currentPath = (String) BeanSerializer.PATH.get();

try {

BeanSerializer.PATH.set(currentPath + "/" + localName);
  //filter the descriptor based on in-context filter spec - cached by spec
id

FilterSpec filterSpec = (FilterSpec)
CallContext.getCurrentContext().getAttribute(
FilterSpec.ATTR_XML_FILTER);

if (filterSpec != null
&& filterSpec.isSuppressed((String)BeanSerializer.PATH.get())) {
return;
}

super.writeElement(namespaceUri, localName, qualifiedName,
elementDescriptor,
context);
  } finally {
BeanSerializer.PATH.set(currentPath);
}
}
  MyBeanSerializer.PATH is a ThreadLocal string that specifies current path
(like /A/B/C/D) and my isSuppressed method compares current path with a list
of paths to-be-suppressed.

Regards,
Maciek