streams-dev mailing list archives

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

    https://github.com/apache/incubator-streams/pull/131#discussion_r20456659
  
    --- Diff: streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseStringActivityConverter.java
---
    @@ -0,0 +1,65 @@
    +package org.apache.streams.converter;
    +
    +import com.fasterxml.jackson.core.JsonProcessingException;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.google.common.collect.Lists;
    +import org.apache.streams.data.ActivityConverter;
    +import org.apache.streams.exceptions.ActivitySerializerException;
    +import org.apache.streams.jackson.StreamsJacksonMapper;
    +import org.apache.streams.pojo.json.Activity;
    +
    +import java.util.List;
    +
    +/**
    + * BaseObjectNodeActivityConverter is included by default in all
    + * @see {@link org.apache.streams.converter.ActivityConverterProcessor}
    + *
    + * Ensures generic String Json representation of an Activity can be converted to Activity
    + *
    + */
    +public class BaseStringActivityConverter implements ActivityConverter<String> {
    +
    +    private ObjectMapper mapper = new StreamsJacksonMapper();
    +
    +    private static BaseStringActivityConverter instance = new BaseStringActivityConverter();
    +
    +    public static BaseStringActivityConverter getInstance() {
    +        return instance;
    +    }
    +
    +
    +    @Override
    +    public String serializationFormat() {
    +        return null;
    +    }
    +
    +    @Override
    +    public String serialize(Activity deserialized) throws ActivitySerializerException
{
    +        try {
    +            return mapper.writeValueAsString(deserialized);
    +        } catch (JsonProcessingException e) {
    +            throw new ActivitySerializerException();
    +        }
    +    }
    +
    +    @Override
    +    public Activity deserialize(String serialized) throws ActivitySerializerException
{
    +        try {
    +            return mapper.readValue(serialized, Activity.class);
    +        } catch (Exception e) {
    +            throw new ActivitySerializerException();
    +        }
    +    }
    +
    +    @Override
    +    public List<Activity> deserializeAll(List<String> serializedList) {
    --- End diff --
    
    BaseObjectNodeActivityConverter and BaseStringActivityConverter both duplicate this method,
could it be abstracted out to another class so that they could both use that implementation?


---
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