Github user devtagare commented on a diff in the pull request:
https://github.com/apache/apex-malhar/pull/348#discussion_r71554968
--- Diff:
library/src/main/java/com/datatorrent/lib/formatter/JsonFormatter.java ---
@@ -45,58 +38,30 @@
@org.apache.hadoop.classification.InterfaceStability.Evolving
public class JsonFormatter extends Formatter<String>
{
+ private transient ObjectMapper objMapper;
private transient ObjectWriter writer;
- protected String dateFormat;
+ @SuppressWarnings("deprecation")
@Override
public void setup(OperatorContext context)
{
- try {
- ObjectMapper mapper = new ObjectMapper();
- if (dateFormat != null) {
- mapper.setDateFormat(new SimpleDateFormat(dateFormat));
- }
- writer = mapper.writerWithType(clazz);
- mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS,
true);
- mapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS,
true);
- mapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS,
true);
- } catch (Throwable e) {
- throw new RuntimeException("Unable find provided class");
- }
+ objMapper = new ObjectMapper();
+ writer = objMapper.writerWithType(clazz);
}
@Override
public String convert(Object tuple)
{
+ if (tuple == null) {
+ return null;
+ }
try {
return writer.writeValueAsString(tuple);
- } catch (JsonGenerationException | JsonMappingException e) {
- logger.debug("Error while converting tuple {}
{}",tuple,e.getMessage());
- } catch (IOException e) {
- DTThrowable.rethrow(e);
+ } catch (JsonProcessingException e) {
+ logger.error("Error while converting tuple {} {}", tuple,
e.getMessage());
}
--- End diff --
Same as above e instead of e.getMessage()
---
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.
---