Search in sources :

Example 1 with ObjectCodec

use of org.codehaus.jackson.ObjectCodec in project spatial-portal by AtlasOfLivingAustralia.

the class LegendDeserializer method deserialize.

@Override
public Legend deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    ObjectMapper om = new ObjectMapper();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    return null;
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) ObjectCodec(org.codehaus.jackson.ObjectCodec) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with ObjectCodec

use of org.codehaus.jackson.ObjectCodec in project samza by apache.

the class SamzaObjectMapper method getObjectMapper.

/**
   * @return Returns a new ObjectMapper that's been configured to (de)serialize
   *         Samza's job data model, and simple data types such as TaskName,
   *         Partition, Config, and SystemStreamPartition.
   */
public static ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule("SamzaModule", new Version(1, 0, 0, ""));
    // Setup custom serdes for simple data types.
    module.addSerializer(Partition.class, new PartitionSerializer());
    module.addSerializer(SystemStreamPartition.class, new SystemStreamPartitionSerializer());
    module.addKeySerializer(SystemStreamPartition.class, new SystemStreamPartitionKeySerializer());
    module.addSerializer(TaskName.class, new TaskNameSerializer());
    module.addDeserializer(Partition.class, new PartitionDeserializer());
    module.addDeserializer(SystemStreamPartition.class, new SystemStreamPartitionDeserializer());
    module.addKeyDeserializer(SystemStreamPartition.class, new SystemStreamPartitionKeyDeserializer());
    module.addDeserializer(Config.class, new ConfigDeserializer());
    // Setup mixins for data models.
    mapper.getSerializationConfig().addMixInAnnotations(TaskModel.class, JsonTaskModelMixIn.class);
    mapper.getDeserializationConfig().addMixInAnnotations(TaskModel.class, JsonTaskModelMixIn.class);
    mapper.getSerializationConfig().addMixInAnnotations(ContainerModel.class, JsonContainerModelMixIn.class);
    mapper.getSerializationConfig().addMixInAnnotations(JobModel.class, JsonJobModelMixIn.class);
    mapper.getDeserializationConfig().addMixInAnnotations(JobModel.class, JsonJobModelMixIn.class);
    module.addDeserializer(ContainerModel.class, new JsonDeserializer<ContainerModel>() {

        @Override
        public ContainerModel deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
            ObjectCodec oc = jp.getCodec();
            JsonNode node = oc.readTree(jp);
            int containerId = node.get("container-id").getIntValue();
            if (node.get("container-id") == null) {
                throw new SamzaException("JobModel did not contain a container-id. This can never happen. JobModel corrupt!");
            }
            String processorId;
            if (node.get("processor-id") == null) {
                processorId = String.valueOf(containerId);
            } else {
                processorId = node.get("processor-id").getTextValue();
            }
            Map<TaskName, TaskModel> tasksMapping = OBJECT_MAPPER.readValue(node.get("tasks"), new TypeReference<Map<TaskName, TaskModel>>() {
            });
            return new ContainerModel(processorId, containerId, tasksMapping);
        }
    });
    // Convert camel case to hyphenated field names, and register the module.
    mapper.setPropertyNamingStrategy(new CamelCaseToDashesStrategy());
    mapper.registerModule(module);
    return mapper;
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) ObjectCodec(org.codehaus.jackson.ObjectCodec) SamzaException(org.apache.samza.SamzaException) ContainerModel(org.apache.samza.job.model.ContainerModel) Version(org.codehaus.jackson.Version) DeserializationContext(org.codehaus.jackson.map.DeserializationContext) TypeReference(org.codehaus.jackson.type.TypeReference) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonParser(org.codehaus.jackson.JsonParser) IOException(java.io.IOException) TaskName(org.apache.samza.container.TaskName) HashMap(java.util.HashMap) Map(java.util.Map) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) TaskModel(org.apache.samza.job.model.TaskModel)

Aggregations

JsonNode (org.codehaus.jackson.JsonNode)2 ObjectCodec (org.codehaus.jackson.ObjectCodec)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SamzaException (org.apache.samza.SamzaException)1 TaskName (org.apache.samza.container.TaskName)1 ContainerModel (org.apache.samza.job.model.ContainerModel)1 TaskModel (org.apache.samza.job.model.TaskModel)1 JsonParser (org.codehaus.jackson.JsonParser)1 JsonProcessingException (org.codehaus.jackson.JsonProcessingException)1 Version (org.codehaus.jackson.Version)1 DeserializationContext (org.codehaus.jackson.map.DeserializationContext)1 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)1 TypeReference (org.codehaus.jackson.type.TypeReference)1