List of usage examples for com.fasterxml.jackson.databind ObjectMapper registerModule
public ObjectMapper registerModule(Module module)
From source file:com.github.ibm.domino.client.BaseClient.java
protected void init(String pathSuffix) throws RuntimeException { if (database == null || database.isEmpty()) { throw new RuntimeErrorException(new Error("Database parameter not found")); }// ww w . j a v a2 s . c om if (ignoreHostNameMatching) { HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); } StringBuilder p = new StringBuilder(); if (pathSuffix != null && !pathSuffix.isEmpty()) { p.append("/mail"); p.append("/").append(database); } p.append("/api/calendar"); if (pathSuffix != null && !pathSuffix.isEmpty()) { p.append("/").append(pathSuffix); } setPath(p.toString()); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.setSerializationInclusion(Include.NON_NULL); // mapper.configure(SerializationFeature. WRITE_NULL_MAP_VALUES, false); mapper.registerModule(new Jackson2HalModule()); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.setSupportedMediaTypes( Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM)); converter.setObjectMapper(mapper); restTemplate = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter)); List<ClientHttpRequestInterceptor> interceptors = Collections .<ClientHttpRequestInterceptor>singletonList(new BasicAuthorizationInterceptor(username, password)); restTemplate.setRequestFactory( new InterceptingClientHttpRequestFactory(restTemplate.getRequestFactory(), interceptors)); }
From source file:com.corundumstudio.socketio.parser.JacksonJsonSupport.java
protected void init(ObjectMapper objectMapper) { SimpleModule module = new SimpleModule(); module.addDeserializer(Event.class, eventDeserializer); module.addDeserializer(JsonObject.class, jsonObjectDeserializer); module.addDeserializer(AckArgs.class, ackArgsDeserializer); objectMapper.registerModule(module); objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true); // TODO If jsonObjectDeserializer will be not enough // TypeResolverBuilder<?> typer = new DefaultTypeResolverBuilder(DefaultTyping.NON_FINAL); // typer.init(JsonTypeInfo.Id.CLASS, null); // typer.inclusion(JsonTypeInfo.As.PROPERTY); // typer.typeProperty(configuration.getJsonTypeFieldName()); // objectMapper.setDefaultTyping(typer); }
From source file:com.muk.services.configuration.ServiceConfig.java
/** * @return A json object mapper used in all muk interactions. *//*from www . j av a 2 s .c o m*/ @Bean(name = { "jsonObjectMapper" }) public ObjectMapper jsonObjectMapper() { final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new PairModule()); mapper.registerModule(new JavaTimeModule()); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); return mapper; }
From source file:nl.knaw.huygens.security.server.ObjectMapperProvider.java
@Override public ObjectMapper getContext(Class<?> type) { ObjectMapper objectMapper = new ObjectMapper(); log.debug("Setting up Jackson ObjectMapper: [{}]", objectMapper); // These are 'dev' settings giving us human readable output. objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); // JodaModule maps DateTime to a flat String (or timestamp, see above) instead of recursively yielding // the entire object hierarchy of DateTime which is way too verbose. objectMapper.registerModule(new JodaModule()); return objectMapper; }
From source file:com.corundumstudio.socketio.protocol.JacksonJsonSupport.java
protected void init(ObjectMapper objectMapper) { SimpleModule module = new SimpleModule(); module.setSerializerModifier(modifier); module.addDeserializer(Event.class, eventDeserializer); module.addDeserializer(AckArgs.class, ackArgsDeserializer); objectMapper.registerModule(module); objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); }
From source file:io.klerch.alexa.state.model.AlexaStateModel.java
/** * Returns a json with key-value-pairs - one for each AlexaStateSave-annotated field in this model configured to be valid * in the given scope/* www. j av a2s. c o m*/ * @param scope The scope a AlexaStateSave-annotated field must have or be part of to be considered in the returned json * @throws AlexaStateException Wraps all inner exceptions and gives you context related to handler and model * @return A json-string with key-value-pairs - one for each AlexaStateSave-annotated field in this model configured to be valid */ public String toJSON(final AlexaScope scope) throws AlexaStateException { // for each scope there is a custom json serializer so initialize the one which corresponds to the given scope final AlexaStateSerializer serializer = AlexaScope.APPLICATION.equals(scope) ? new AlexaAppStateSerializer() : AlexaScope.USER.equals(scope) ? new AlexaUserStateSerializer() : new AlexaSessionStateSerializer(); // associate a mapper with the serializer final ObjectMapper mapper = new ObjectMapper(); final SimpleModule module = new SimpleModule(); module.addSerializer(this.getClass(), serializer); mapper.registerModule(module); try { // serialize model which only contains those fields tagged with the given scope return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { final String error = String.format("Error while serializing model of '%1$s' as Json.", this); log.error(error, e); throw AlexaStateException.create(error).withCause(e).withModel(this).build(); } }
From source file:net.udidb.server.driver.ServerModule.java
@Override protected void configure() { // JSON configuration SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(ExpressionValue.class, new ExpressionValueSerializer()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.addMixInAnnotations(VoidResult.class, VoidResultMixIn.class); objectMapper.addMixInAnnotations(DeferredResult.class, DeferredResultMixIn.class); objectMapper.addMixInAnnotations(TableResult.class, TableResultMixIn.class); objectMapper.addMixInAnnotations(ValueResult.class, ValueResultMixIn.class); objectMapper.addMixInAnnotations(TableRow.class, TableRowMixIn.class); objectMapper.registerModule(simpleModule); bind(ObjectMapper.class).toInstance(objectMapper); // REST API configuration Vertx vertx = new VertxFactoryImpl().vertx(); bind(Vertx.class).toInstance(vertx); // Engine configuration bind(String[].class).annotatedWith(Names.named("OP_PACKAGES")) .toInstance(new String[] { "net.udidb.engine.ops.impls" }); bind(DebuggeeContextManager.class).to(DebuggeeContextManagerImpl.class); bind(HelpMessageProvider.class).asEagerSingleton(); bind(UdiProcessManager.class).toInstance(new UdiProcessManagerImpl()); bind(BinaryReader.class).toInstance(new CrossPlatformBinaryReader()); bind(ExpressionCompiler.class).toInstance(new ExpressionCompilerDelegate()); bind(SourceLineRowFactory.class).toInstance(new InMemorySourceLineRowFactory()); bind(ServerEngine.class).to(ServerEngineImpl.class); bind(OperationResultVisitor.class).to(OperationEngine.class); bind(ServerEventDispatcher.class).asEagerSingleton(); bind(EventPump.class).asEagerSingleton(); bind(EventSink.class).to(ServerEventDispatcher.class); WampRouter wampRouter = configureWampRouter(); bind(WampRouter.class).toInstance(wampRouter); bind(WampClient.class).toInstance(configureWampClient(wampRouter)); }
From source file:it.eng.spagobi.engines.network.bean.JSONNetwork.java
/** * JSON serializer for this object/*from w ww . j av a 2 s . com*/ * @return the network serialized * @throws SerializationException */ @JsonIgnore public String getNetworkAsString() throws SerializationException { ObjectMapper mapper = new ObjectMapper(); String s = ""; try { SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, null)); simpleModule.addSerializer(Node.class, new NodeJSONSerializer()); simpleModule.addSerializer(Edge.class, new EdgeJSONSerializer()); mapper.registerModule(simpleModule); s = mapper.writeValueAsString((JSONNetwork) this); } catch (Exception e) { throw new SerializationException("Error serializing the network", e); } s = StringEscapeUtils.unescapeJavaScript(s); return s; }
From source file:ijfx.service.ui.ImageJInfoService.java
@AngularMethod(sync = true, description = "Return the list of all widgets", inputDescription = "No input") public JSObject getModuleList() { try {//from www.j a va 2 s . c om ObjectMapper mapper = new ObjectMapper(); logger.fine("Getting module list"); SimpleModule simpleModule = new SimpleModule("ModuleSerializer"); // simpleModule.addSerializer(ModuleItem<?>.class,new ModuleItemSerializer()); simpleModule.addSerializer(ModuleInfo.class, new ModuleSerializer()); simpleModule.addSerializer(ModuleItem.class, new ModuleItemSerializer()); mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.registerModule(simpleModule); ArrayNode arrayNode = mapper.createArrayNode(); moduleService.getModules().forEach(module -> { //System.out.println("Adding "+module.getName()); arrayNode.add(mapper.convertValue(module, JsonNode.class)); }); //String json = mapper.writeValueAsString(moduleService.getModules()); logger.fine("JSON done !"); return JSONUtils.parseToJSON(appService.getCurrentWebEngine(), arrayNode.toString()); //return JSONUtils.parseToJSON(appService.getCurrentWebEngine(), json); } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } logger.warning("Returning null"); return null; }
From source file:com.orange.ngsi.ConvertersConfiguration.java
@Bean public MappingJackson2HttpMessageConverter jsonV1Converter(ObjectMapper objectMapper) { // Serialize numbers as strings objectMapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true); // Serialize booleans as strings SimpleModule booleanAsString = new SimpleModule("BooleanAsString"); booleanAsString.addSerializer(Boolean.class, new JsonSerializer<Boolean>() { @Override// w w w . ja v a 2s.c om public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(value.toString()); } }); objectMapper.registerModule(booleanAsString); objectMapper.addMixIn(ContextElement.class, EntityIdMixIn.class); objectMapper.addMixIn(AppendContextElementResponse.class, EntityIdMixIn.class); return new MappingJackson2HttpMessageConverter(objectMapper); }