/** * Fluent-style alternative to {@link #registerModule}; functionally equivalent to: *<pre> * mapper.registerModule(module); * return mapper; *</pre> * NOTE: name is unfortunately misleading in suggesting that a new instance * might be created (as is the case with most other 'withXxx()' methods * for Jackson core objects) -- this is not the case; rather, this is just * a variant of {@link #registerModule} but one that returns 'this' * (like it should return, but does not for historical reasons). * * @since 1.8 */ public ObjectMapper withModule(Module module) { registerModule(module); return this; }
/** * Fluent-style alternative to {@link #registerModule}; functionally equivalent to: *<pre> * mapper.registerModule(module); * return mapper; *</pre> * NOTE: name is unfortunately misleading in suggesting that a new instance * might be created (as is the case with most other 'withXxx()' methods * for Jackson core objects) -- this is not the case; rather, this is just * a variant of {@link #registerModule} but one that returns 'this' * (like it should return, but does not for historical reasons). * * @since 1.8 */ public ObjectMapper withModule(Module module) { registerModule(module); return this; }
public ObjectMapperProvider(){ mapper = new ObjectMapper().enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY).enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL) .setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).setVisibility(JsonMethod.FIELD, Visibility.ANY); mapper.registerModule(new MrBeanModule()); }
public JacksonJsonProvider create(Iterable<? extends Module> modules) { ObjectMapper mapper = new ObjectMapper(); /* This is what MapperConfigurator would do to a default ObjectMapper */ AnnotationIntrospector intr = AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector()); mapper.setDeserializationConfig(mapper.getDeserializationConfig().withAnnotationIntrospector(intr)); mapper.setSerializationConfig(mapper.getSerializationConfig().withAnnotationIntrospector(intr)); /* In the absence of a specific annotation for @JsonSerialize(include), ignore null fields when serializing */ mapper.setSerializationInclusion(Inclusion.NON_NULL); for (Module module : modules) { mapper.registerModule(module); } mapper.registerModule(new GuavaIterableCapableModule()); JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(mapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS); // Make sure we only rely on annotations for de-/serialization provider.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false); provider.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, false); provider.configure(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, false); provider.configure(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, false); return provider; } }
/** * Registers a module that can extend functionality provided by this class; for example, by * adding providers for custom serializers and deserializers. * * @param module Module to register * @see ObjectMapper#registerModule(org.codehaus.jackson.map.Module) */ public void registerModule(Module module) { mapper.registerModule(module); }
/** * * Register a Jackson configuration {@link Module} to set special rules for de-serialization * * @param module to register */ public void registerModule(Module module) { objectMapper.registerModule(module); }
@Override public ObjectMapper getContext(Class<?> type) { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GeoJsonModule()); return mapper; }
@PostConstruct public void bindMessageConverters() { ObjectMapper mapper = new ObjectMapper(); // mapper.setDateFormat(new // SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS")); // SerializationConfig sc = mapper.getSerializationConfig(); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); mapper.registerModule(JacksonContextResolver.getCustomSimpleModuleWithXSS()); customMappingJacksonHttpMessageConverter.setObjectMapper(mapper); }
@Override protected MappingJacksonHttpMessageConverter getJsonMessageConverter() { MappingJacksonHttpMessageConverter converter = super .getJsonMessageConverter(); objectMapper = new ObjectMapper(); objectMapper.registerModule(new WeiboModule()); converter.setObjectMapper(objectMapper); return converter; }
public JacksonJsonMapper(Class<T> type) { this.type = type; objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule("Atlassian Diagnostics Built-in", new Version(1, 0, 0, null)); // register a deserializer for ThreadDump to unmarshal it as a SimpleThreadDump module.addDeserializer(ThreadDump.class, new JsonDeserializer<ThreadDump>() { @Override public ThreadDump deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { return jp.readValueAs(SimpleThreadDump.class); } }); objectMapper.registerModule(module); }
private void formatProcessingStatusAsJson(ProcessingStatusType pst) throws JsonGenerationException, JsonMappingException, IOException { // serialize to JSON using Jackson (part of Mule ESB dependencies, Mule // 3.3 bundles Jackson 1.8) ObjectMapper om = new ObjectMapper(); SimpleModule customSerializerMod = new SimpleModule( "CustomSerializerModule", new Version(1, 0, 0, null)); customSerializerMod.addSerializer(new JsonCustomSerializer()); om.registerModule(customSerializerMod); procStatus = om.writeValueAsString(pst.getProcessingStatusList()); }
/** * Configure the given object mapper to be used with the Mongo Jackson Mapper. Please call this method rather than * calling objectMapper.with(MongoJacksonMapperModule.INSTANCE), because Jacksons module system doesn't allow the * mongo jackson mapper to do all the configuration it needs to do. This method will do that configuration though. * * @param objectMapper The object mapper to configure * @return This object mapper (for chaining) */ public static ObjectMapper configure(ObjectMapper objectMapper) { objectMapper.registerModule(INSTANCE); objectMapper.setHandlerInstantiator(new MongoJacksonHandlerInstantiator( new MongoAnnotationIntrospector(objectMapper.getDeserializationConfig()))); return objectMapper; }
/** * <p>Constructor for JacksonObjectMapperProvider.</p> */ public JacksonObjectMapperProvider() { this.objectMapper = new ObjectMapper(); objectMapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true); objectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); module.addSerializer(ObjectMapperString.class, new RawSerializer<>(Object.class)); module.addSerializer(JSONObject.class, new RawSerializer<>(Object.class)); module.addSerializer(JSONArray.class, new RawSerializer<>(Object.class)); objectMapper.registerModule(module); }
public static final ObjectMapper getObjectMapper() { final ObjectMapper mapper = new ObjectMapper(); final SimpleModule gnipActivityModule = new SimpleModule("gnip.activity", new Version(1, 0, 0, null)); gnipActivityModule.addDeserializer(Geo.class, new GeoDeserializer(Geo.class)); gnipActivityModule.addSerializer(Geo.class, new GeoSerializer()); mapper.registerModule(gnipActivityModule); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, false); return mapper; }
private static ObjectMapper createObjectMapper() { // it's a shame that the serialization and deserialization mechanism // used aren't symmetric... but it works. final DeserializerProvider deserializerProvider = new StdDeserializerProvider(new JsonRepresentationDeserializerFactory()); final ObjectMapper objectMapper = new ObjectMapper(null, null, deserializerProvider); final SimpleModule jsonModule = new SimpleModule("json", new Version(1, 0, 0, null)); jsonModule.addSerializer(JsonRepresentation.class, new JsonRepresentationSerializer()); objectMapper.registerModule(jsonModule); objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
private static ObjectMapper createObjectMapper() { // it's a shame that the serialization and deserialization mechanism // used aren't symmetric... but it works. final DeserializerProvider deserializerProvider = new StdDeserializerProvider(new JsonRepresentationDeserializerFactory()); final ObjectMapper objectMapper = new ObjectMapper(null, null, deserializerProvider); final SimpleModule jsonModule = new SimpleModule("json", new Version(1, 0, 0, null)); jsonModule.addSerializer(JsonRepresentation.class, new JsonRepresentationSerializer()); objectMapper.registerModule(jsonModule); objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
public static ObjectMapper createCustomMapper() { ObjectMapper result = new ObjectMapper(); result.configure(Feature.INDENT_OUTPUT, true); SimpleModule module = createhRavenModule(); addJobMappings(module); module.addSerializer(Flow.class, new FlowSerializer()); module.addSerializer(AppSummary.class, new AppSummarySerializer()); module.addSerializer(TaskDetails.class, new TaskDetailsSerializer()); module.addSerializer(JobDetails.class, new JobDetailsSerializer()); result.registerModule(module); return result; }
public static ObjectMapper createCustomMapper() { ObjectMapper result = new ObjectMapper(); result.configure(Feature.INDENT_OUTPUT, true); SimpleModule module = createhRavenModule(); addJobMappings(module); module.addSerializer(Flow.class, new FlowSerializer()); module.addSerializer(AppSummary.class, new AppSummarySerializer()); module.addSerializer(TaskDetails.class, new TaskDetailsSerializer()); module.addSerializer(JobDetails.class, new JobDetailsSerializer()); result.registerModule(module); return result; }
private ObjectMapper createJsonMapper() { ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule("LlamaModule", new Version(1, 0, 0, null)); module.addSerializer(new UUIDSerializer()); module.addSerializer(new ClientInfoImplSerializer()); module.addSerializer(new PlacedReservationSerializer()); module.addSerializer(new PlacedResourceSerializer()); mapper.registerModule(module); mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); return mapper; }
@Override public void onEvent(Event event, Object source, Object data) { for (ConverterHelper converter : Engine.getInstance().getRegisteredConverters()) { if (converter instanceof JacksonConverter) { JacksonConverter jconverter = (JacksonConverter) converter; SimpleModule m = new SimpleModule("org.json", new Version(1, 0, 0, null)); m.addSerializer(JSONObject.class, new JSONObjectSerializer()); m.addSerializer(JSONArray.class, new JSONArraySerializer()); jconverter.getObjectMapper().registerModule(m); } } }