org.codehaus.jackson.map.JsonDeserializer Java Examples
The following examples show how to use
org.codehaus.jackson.map.JsonDeserializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BackportedObjectReader.java From elasticsearch-hadoop with Apache License 2.0 | 6 votes |
/** * Method called to locate deserializer for the passed root-level value. */ protected JsonDeserializer<Object> _findRootDeserializer(DeserializationConfig cfg, JavaType valueType) throws JsonMappingException { // Sanity check: must have actual type... if (valueType == null) { throw new JsonMappingException("No value type configured for ObjectReader"); } // First: have we already seen it? JsonDeserializer<Object> deser = _rootDeserializers.get(valueType); if (deser != null) { return deser; } // es-hadoop: findType with 2 args have been removed since 1.9 so this code compiles on 1.8 (which has the fallback method) // es-hadoop: on 1.5 only the 2 args method exists, since 1.9 only the one with 3 args hence the if // Nope: need to ask provider to resolve it deser = _provider.findTypedValueDeserializer(cfg, valueType); if (deser == null) { // can this happen? throw new JsonMappingException("Can not find a deserializer for type " + valueType); } _rootDeserializers.put(valueType, deser); return deser; }
Example #2
Source File: BackportedJacksonMappingIterator.java From elasticsearch-hadoop with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected BackportedJacksonMappingIterator(JavaType type, JsonParser jp, DeserializationContext ctxt, JsonDeserializer<?> deser) { _type = type; _parser = jp; _context = ctxt; _deserializer = (JsonDeserializer<T>) deser; /* One more thing: if we are at START_ARRAY (but NOT root-level * one!), advance to next token (to allow matching END_ARRAY) */ if (jp != null && jp.getCurrentToken() == JsonToken.START_ARRAY) { JsonStreamContext sc = jp.getParsingContext(); // safest way to skip current token is to clear it (so we'll advance soon) if (!sc.inRoot()) { jp.clearCurrentToken(); } } }
Example #3
Source File: JsonDeserializationBehavior.java From jwala with Apache License 2.0 | 5 votes |
private CustomDeserializerFactory createFactory() { final CustomDeserializerFactory factory = new CustomDeserializerFactory(); for (final Map.Entry<Class, JsonDeserializer> mapping : mappings.entrySet()) { factory.addSpecificMapping(mapping.getKey(), mapping.getValue()); } return factory; }
Example #4
Source File: JsonUnknownPropertyHandler.java From spring-data-simpledb with MIT License | 5 votes |
@Override public boolean handleUnknownProperty(DeserializationContext ctxt, JsonDeserializer<?> deserializer, Object beanOrClass, String propertyName) throws IOException { JsonParser jsonParser = ctxt.getParser(); LOG.warn("Unknown Json property: " + propertyName); jsonParser.skipChildren(); return true; }
Example #5
Source File: JsonDeserializationBehavior.java From jwala with Apache License 2.0 | 4 votes |
public <T> JsonDeserializationBehavior addMapping(final Class<T> aClass, final JsonDeserializer<T> aDeserializer) { mappings.put(aClass, aDeserializer); return this; }
Example #6
Source File: SamzaObjectMapper.java From samza with Apache License 2.0 | 4 votes |
/** * @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.addSerializer(TaskMode.class, new TaskModeSerializer()); module.addDeserializer(TaskName.class, new TaskNameDeserializer()); module.addDeserializer(Partition.class, new PartitionDeserializer()); module.addDeserializer(SystemStreamPartition.class, new SystemStreamPartitionDeserializer()); module.addKeyDeserializer(SystemStreamPartition.class, new SystemStreamPartitionKeyDeserializer()); module.addDeserializer(Config.class, new ConfigDeserializer()); module.addDeserializer(TaskMode.class, new TaskModeDeserializer()); // 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); /* * Before Samza 0.13, "container-id" was used. * In Samza 0.13, "processor-id" was added to be the id to use and "container-id" was deprecated. However, * "container-id" still needed to be checked for backwards compatibility in case "processor-id" was missing * (i.e. from a job model corresponding to a version of the job that was on a pre Samza 0.13 version). * In Samza 1.0, "container-id" was further cleaned up from ContainerModel. This logic is still being left here * as a fallback for backwards compatibility with pre Samza 0.13. ContainerModel.getProcessorId was changed to * ContainerModel.getId in the Java API, but "processor-id" still needs to be used as the JSON key for backwards * compatibility with Samza 0.13 and Samza 0.14. */ String id; if (node.get(JsonContainerModelMixIn.PROCESSOR_ID_KEY) == null) { if (node.get(JsonContainerModelMixIn.CONTAINER_ID_KEY) == null) { throw new SamzaException( String.format("JobModel was missing %s and %s. This should never happen. JobModel corrupt!", JsonContainerModelMixIn.PROCESSOR_ID_KEY, JsonContainerModelMixIn.CONTAINER_ID_KEY)); } id = String.valueOf(node.get(JsonContainerModelMixIn.CONTAINER_ID_KEY).getIntValue()); } else { id = node.get(JsonContainerModelMixIn.PROCESSOR_ID_KEY).getTextValue(); } Map<TaskName, TaskModel> tasksMapping = OBJECT_MAPPER.readValue(node.get(JsonContainerModelMixIn.TASKS_KEY), new TypeReference<Map<TaskName, TaskModel>>() { }); return new ContainerModel(id, tasksMapping); } }); // Convert camel case to hyphenated field names, and register the module. mapper.setPropertyNamingStrategy(new CamelCaseToDashesStrategy()); mapper.registerModule(module); return mapper; }