streams-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From steveblackmon <...@git.apache.org>
Subject [GitHub] incubator-streams pull request: Streams 68,218
Date Mon, 17 Nov 2014 20:52:21 GMT
Github user steveblackmon commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/131#discussion_r20464027
  
    --- Diff: streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseDocumentClassifier.java
---
    @@ -0,0 +1,66 @@
    +package org.apache.streams.converter;
    +
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ObjectNode;
    +import com.google.common.base.Preconditions;
    +import org.apache.streams.data.DocumentClassifier;
    +import org.apache.streams.data.util.ActivityUtil;
    +import org.apache.streams.jackson.StreamsJacksonMapper;
    +import org.apache.streams.pojo.json.Activity;
    +
    +import java.io.IOException;
    +
    +/**
    + * BaseDocumentClassifier is included by default in all
    + * @see {@link org.apache.streams.converter.ActivityConverterProcessor}
    + *
    + * Ensures generic String and ObjectNode documents can be converted to Activity
    + *
    + */
    +public class BaseDocumentClassifier implements DocumentClassifier {
    +
    +    private static BaseDocumentClassifier instance = new BaseDocumentClassifier();
    +
    +    public static BaseDocumentClassifier getInstance() {
    +        return instance;
    +    }
    +
    +    private ObjectMapper mapper = StreamsJacksonMapper.getInstance();
    +
    +    @Override
    +    public Class detectClass(Object document) {
    +        Preconditions.checkArgument(
    +                document instanceof String
    +             || document instanceof ObjectNode);
    +
    +        Activity activity = null;
    +        ObjectNode node = null;
    +
    +        // Soon javax.validation will available in jackson
    +        //   That will make this simpler and more powerful
    +        if( document instanceof String ) {
    +            try {
    +                activity = this.mapper.readValue((String)document, Activity.class);
    --- End diff --
    
    Those issues only occur when document is not a String.  This line will only execute if
document instanceof String evaluated true, so this cast should be sufficient and more efficient
than involving mapper.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message