[
https://issues.apache.org/jira/browse/APEXMALHAR-2157?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15386102#comment-15386102
]
ASF GitHub Bot commented on APEXMALHAR-2157:
--------------------------------------------
Github user devtagare commented on a diff in the pull request:
https://github.com/apache/apex-malhar/pull/348#discussion_r71554876
--- 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());
--- End diff --
logger.debug("Error while converting tuple {} {}",tuple,e); instead of
e.getMessage() its in debug mode
> Improvements in JSON Formatter
> ------------------------------
>
> Key: APEXMALHAR-2157
> URL: https://issues.apache.org/jira/browse/APEXMALHAR-2157
> Project: Apache Apex Malhar
> Issue Type: Improvement
> Reporter: shubham pathak
> Assignee: shubham pathak
> Priority: Minor
>
> We need following features in existing JSON Formatter
> 1. Ability to provide date format for different date fields in POJO. Current
> implementation accepts just one format and applies the same to all date
> fields.
> 2. Ability to provide JSON field to POJO field mapping.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)