Search in sources :

Example 1 with TypeFactory

use of org.codehaus.jackson.map.type.TypeFactory in project motech by motech.

the class TaskDeserializer method deserialize.

@Override
public Task deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    jsonNode = jsonParser.readValueAsTree();
    task = new Task();
    ObjectCodec codec = jsonParser.getCodec();
    if (codec instanceof ObjectMapper) {
        mapper = (ObjectMapper) codec;
    } else {
        mapper = new ObjectMapper();
    }
    TypeFactory typeFactory = mapper.getTypeFactory();
    JavaType stringType = typeFactory.constructType(String.class);
    JavaType longType = typeFactory.constructType(Long.class);
    JavaType intType = typeFactory.constructType(Integer.class);
    JavaType dateTime = typeFactory.constructType(DateTime.class);
    JavaType booleanType = typeFactory.constructType(boolean.class);
    JavaType timeType = typeFactory.constructType(Time.class);
    setProperty("id", longType);
    setProperty("owner", stringType);
    setProperty("creator", stringType);
    setProperty("creationDate", dateTime);
    setProperty("modificationDate", dateTime);
    setProperty("modifiedBy", stringType);
    setProperty("description", stringType);
    setProperty("name", stringType);
    setProperty("enabled", stringType);
    setProperty("hasRegisteredChannel", stringType);
    setProperty("taskConfig", typeFactory.constructType(TaskConfig.class));
    setProperty("trigger", typeFactory.constructType(TaskTriggerInformation.class));
    setProperty("numberOfRetries", intType);
    setProperty("retryIntervalInMilliseconds", intType);
    setProperty("retryTaskOnFailure", stringType);
    setProperty("useTimeWindow", booleanType);
    setProperty("startTime", timeType);
    setProperty("endTime", timeType);
    setProperty("validationErrors", typeFactory.constructCollectionType(Set.class, TaskError.class));
    setProperty("actions", typeFactory.constructCollectionType(List.class, TaskActionInformation.class));
    setProperty("days", typeFactory.constructCollectionType(List.class, String.class));
    return task;
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) JavaType(org.codehaus.jackson.type.JavaType) Set(java.util.Set) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) List(java.util.List) ObjectCodec(org.codehaus.jackson.ObjectCodec) TypeFactory(org.codehaus.jackson.map.type.TypeFactory) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with TypeFactory

use of org.codehaus.jackson.map.type.TypeFactory in project incubator-gobblin by apache.

the class KafkaCheckpoint method deserialize.

public static KafkaCheckpoint deserialize(InputStream inputStream) throws IOException {
    TypeFactory typeFactory = _mapper.getTypeFactory();
    MapType mapType = typeFactory.constructMapType(HashMap.class, Integer.class, Long.class);
    HashMap<Integer, Long> checkpoint = _mapper.readValue(inputStream, mapType);
    return new KafkaCheckpoint(checkpoint);
}
Also used : TypeFactory(org.codehaus.jackson.map.type.TypeFactory) MapType(org.codehaus.jackson.map.type.MapType)

Aggregations

TypeFactory (org.codehaus.jackson.map.type.TypeFactory)2 List (java.util.List)1 Set (java.util.Set)1 ObjectCodec (org.codehaus.jackson.ObjectCodec)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 MapType (org.codehaus.jackson.map.type.MapType)1 JavaType (org.codehaus.jackson.type.JavaType)1 Task (org.motechproject.tasks.domain.mds.task.Task)1 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)1 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)1 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)1 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)1