Github user chandnisingh commented on a diff in the pull request:

    
https://github.com/apache/incubator-apex-malhar/pull/137#discussion_r47725172
  
    --- Diff: 
library/src/main/java/com/datatorrent/lib/formatter/XmlFormatter.java ---
    @@ -57,45 +55,32 @@ public XmlFormatter()
       }
     
       @Override
    -  public void activate(Context context)
    +  public void setup(OperatorContext context)
       {
    -    if (prettyPrint) {
    -      xstream = new XStream();
    -    } else {
    -      xstream = new XStream(new XppDriver()
    -      {
    -        @Override
    -        public HierarchicalStreamWriter createWriter(Writer out)
    -        {
    -          return new CompactWriter(out, getNameCoder());
    -        }
    -      });
    -    }
    -    if (alias != null) {
    -      try {
    -        xstream.alias(alias, clazz);
    -      } catch (Throwable e) {
    -        throw new RuntimeException("Unable find provided class");
    -      }
    -    }
    -    if (dateFormat != null) {
    -      xstream.registerConverter(new DateConverter(dateFormat, new String[] 
{}));
    +    JAXBContext ctx;
    +    try {
    +      ctx = JAXBContext.newInstance(getClazz());
    +      marshaller = ctx.createMarshaller();
    +      marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    +      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, 
prettyPrint);
    +    } catch (JAXBException e) {
    +      DTThrowable.wrapIfChecked(e);
         }
       }
     
       @Override
    -  public void deactivate()
    -  {
    -
    -  }
    -
    -  @Override
       public String convert(Object tuple)
       {
         try {
    -      return xstream.toXML(tuple);
    -    } catch (XStreamException e) {
    -      logger.debug("Error while converting tuple {} {} 
",tuple,e.getMessage());
    +      StringWriter writer = new StringWriter();
    +      if (getAlias() != null) {
    +        marshaller.marshal(new JAXBElement(new QName(getAlias()), 
tuple.getClass(), tuple), writer);
    +      } else {
    +        marshaller.marshal(new JAXBElement(new 
QName(getClazz().getSimpleName()), tuple.getClass(), tuple), writer);
    +      }
    +      return writer.toString();
    +    } catch (Exception e) {
    +      logger.debug("Error while converting tuple {} {} ", tuple, 
e.getMessage());
           return null;
    --- End diff --
    
    Swallowing exception?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to