List of usage examples for com.fasterxml.jackson.databind.module SimpleModule SimpleModule
public SimpleModule()
From source file:eu.trentorise.opendata.semtext.jackson.test.SemTextModuleTest.java
/** * Registers MyMetadata in objectMapper//from w w w.j a v a 2s.c om */ private void registerMyMetadata() { objectMapper.registerModule(new SimpleModule() { { setMixInAnnotation(MyMetadata.class, MyMetadataJackson.class); } }); }
From source file:de.javagl.jgltf.model.io.JacksonUtils.java
/** * Perform a default configuration of the given object mapper for * parsing glTF data/*from ww w . j av a 2 s . c o m*/ * * @param objectMapper The object mapper * @param jsonErrorConsumer The consumer for {@link JsonError}s. If this * is <code>null</code>, then the errors will not be handled. * <code>null</code>, then log outputs will be created for the errors */ static void configure(ObjectMapper objectMapper, Consumer<? super JsonError> jsonErrorConsumer) { // Some glTF files have single values instead of arrays, // so accept this for compatibility reasons objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.addHandler(createDeserializationProblemHandler(jsonErrorConsumer)); // Register the module that will initialize the setup context // with the error handling bean deserializer modifier objectMapper.registerModule(new SimpleModule() { /** * Serial UID */ private static final long serialVersionUID = 1L; @Override public void setupModule(SetupContext context) { super.setupModule(context); context.addBeanDeserializerModifier(createErrorHandlingBeanDeserializerModifier(jsonErrorConsumer)); } }); }
From source file:com.heliosapm.tsdblite.json.JSON.java
/** * Registers a ser/deser pair for the passed class * @param clazz The class for which a ser/deser pair is being registered * @param deser The deserializer// ww w .j a v a2s .c o m * @param ser The serializer */ public static <T> void registerSerialization(final Class<T> clazz, final JsonDeserializer<T> deser, final JsonSerializer<T> ser) { if (clazz == null) throw new IllegalArgumentException("The passed class was null"); if (ser == null) throw new IllegalArgumentException("The passed serializer for [" + clazz.getName() + "] was null"); if (deser == null) throw new IllegalArgumentException("The passed deserializer for [" + clazz.getName() + "] was null"); final SimpleModule module = new SimpleModule(); int added = 0; module.addSerializer(clazz, ser); module.addDeserializer(clazz, deser); if (added > 0) jsonMapper.registerModule(module); }
From source file:com.onedrive.api.OneDrive.java
public RestTemplate getRestTemplate() { if (restTemplate == null) { DefaultAccessTokenRequest accessTokenRequest = new DefaultAccessTokenRequest(); accessTokenRequest.setAuthorizationCode(authorizationCode); accessTokenRequest.setPreservedState(new Object()); accessTokenRequest.setExistingToken(getOAuth2AccessToken()); restTemplate = new OAuth2RestTemplate(getResourceDetails(), new DefaultOAuth2ClientContext(accessTokenRequest)); restTemplate.setErrorHandler(new OneDriveErrorHandler(restTemplate.getMessageConverters())); AccessTokenProviderChain provider = new AccessTokenProviderChain( Arrays.asList(new AuthorizationCodeAccessTokenProvider())); provider.setClientTokenServices(new InternalTokenServices(this)); ((OAuth2RestTemplate) restTemplate).setAccessTokenProvider(provider); restTemplate.getMessageConverters().add(new MultipartRelatedHttpMessageConverter()); for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) { if (mc instanceof MappingJackson2HttpMessageConverter) { objectMapper = ((MappingJackson2HttpMessageConverter) mc).getObjectMapper(); objectMapper.setInjectableValues(new InjectableValues.Std().addValue(OneDrive.class, this)); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); SimpleModule module = new SimpleModule(); module.addDeserializer(Date.class, new InternalDateDeserializer()); objectMapper.registerModule(module); }//from w w w . j a va 2s . c om } } return restTemplate; }
From source file:io.swagger.inflector.SwaggerInflector.java
protected void init(Configuration configuration) { config = configuration;//ww w. j a v a 2 s . c o m Swagger swagger = new SwaggerParser().read(config.getSwaggerUrl(), null, true); if (swagger != null) { originalBasePath = swagger.getBasePath(); StringBuilder b = new StringBuilder(); if (!"".equals(configuration.getRootPath())) b.append(configuration.getRootPath()); if (swagger.getBasePath() != null) { b.append(swagger.getBasePath()); } if (b.length() > 0) { swagger.setBasePath(b.toString()); } Map<String, Path> paths = swagger.getPaths(); Map<String, Model> definitions = swagger.getDefinitions(); for (String pathString : paths.keySet()) { Path path = paths.get(pathString); final Resource.Builder builder = Resource.builder(); this.basePath = configuration.getRootPath() + swagger.getBasePath(); builder.path(basePath(originalBasePath, pathString)); Operation operation; operation = path.getGet(); if (operation != null) { addOperation(pathString, builder, HttpMethod.GET, operation, definitions); } operation = path.getPost(); if (operation != null) { addOperation(pathString, builder, HttpMethod.POST, operation, definitions); } operation = path.getPut(); if (operation != null) { addOperation(pathString, builder, HttpMethod.PUT, operation, definitions); } operation = path.getDelete(); if (operation != null) { addOperation(pathString, builder, HttpMethod.DELETE, operation, definitions); } operation = path.getOptions(); if (operation != null) { addOperation(pathString, builder, HttpMethod.OPTIONS, operation, definitions); } operation = path.getPatch(); if (operation != null) { addOperation(pathString, builder, "PATCH", operation, definitions); } registerResources(builder.build()); } // enable swagger JSON enableSwaggerJSON(swagger); // enable swagger YAML enableSwaggerYAML(swagger); } else { LOGGER.error("No swagger definition detected! Not much to do..."); } // JSON register(JacksonJsonProvider.class); // XML register(JacksonJaxbXMLProvider.class); register(new MultiPartFeature()); // Swagger serializers register(SwaggerSerializers.class); // XML mapper SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(new JsonExampleSerializer()); Json.mapper().registerModule(simpleModule); Yaml.mapper().registerModule(simpleModule); // Example serializer register(ExampleSerializer.class); }
From source file:com.logsniffer.event.es.EsEventPersistence.java
@PostConstruct private void initJsonMapper() { jsonMapper = new ObjectMapper(); jsonMapper.configure(MapperFeature.USE_STATIC_TYPING, true); jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); jsonMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true); jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); jsonMapper.registerSubtypes(LogEntry.class); final SimpleModule esModule = new SimpleModule(); esModule.addSerializer(LogPointer.class, new EsLogPointerSerializer()); esModule.addDeserializer(LogPointer.class, new EsLogPointerDeserializer()); esModule.addDeserializer(JsonLogPointer.class, new EsLogPointerDeserializer()); jsonMapper.registerModule(esModule); }
From source file:nl.ortecfinance.opal.jacksonweb.IncomePlanningSimulationRequestTest.java
@Test public void testDoubleSerializer() throws IOException { IncomePlanningSimulationRequest req = new IncomePlanningSimulationRequest(); req.setMyPrimitiveDouble(3.4);//from ww w. ja v a 2 s . c o m req.setMyObjectDouble(Double.parseDouble("3.9")); final double[] doubleArray = new double[] { 2.1, 2, 2 }; req.setMyPrimitiveDoubleArray(doubleArray); double[][] my2DimArray = new double[2][2]; my2DimArray[0] = new double[] { 2.333333, 2.2555555 }; my2DimArray[1] = new double[] { 8.1, 8.3 }; System.out.println("doubleArray:" + doubleArray); System.out.println("my2DimArray:" + my2DimArray); req.setMyPrimitiveDouble2DimArray(my2DimArray); Double[] myObjectDoubleArray = { Double.parseDouble("4.3"), Double.parseDouble("4.5") }; req.setMyObjectDoubleArray(myObjectDoubleArray); SimpleModule module = new SimpleModule(); module.addSerializer(Double.class, new MyDoubleSerializer()); module.addSerializer(double.class, new MyDoubleSerializer()); module.addSerializer(Double[].class, new MyDoubleArraySerializer()); module.addSerializer(double[].class, new MyPrimitiveDoubleArraySerializer()); module.addSerializer(double[][].class, new MyPrimitive2DimDoubleArraySerializer()); module.addSerializer(double[][].class, new MyPrimitive2DimDoubleArraySerializer()); ObjectMapper m = new ObjectMapper(); m.registerModule(module); StringWriter sw = new StringWriter(); m.writeValue(sw, req); String json = sw.toString(); System.out.println("testSerializeDate:" + json); }
From source file:com.spotify.ffwd.AgentCore.java
/** * Setup early application Injector.//from w w w . j a v a2 s . co m * * The early injector is used by modules to configure the system. * * @throws Exception If something could not be set up. */ private Injector setupEarlyInjector() throws Exception { final List<Module> modules = Lists.newArrayList(); modules.add(new AbstractModule() { @Singleton @Provides @Named("application/yaml+config") public SimpleModule configModule() { final SimpleModule module = new SimpleModule(); // Make InputPlugin, and OutputPlugin sub-type aware through the 'type' attribute. module.setMixInAnnotation(InputPlugin.class, FasterXmlSubTypeMixIn.class); module.setMixInAnnotation(OutputPlugin.class, FasterXmlSubTypeMixIn.class); return module; } @Override protected void configure() { bind(PluginContext.class).to(PluginContextImpl.class).in(Scopes.SINGLETON); } }); final Injector injector = Guice.createInjector(modules); for (final FastForwardModule m : loadModules(injector)) { log.info("Setting up {}", m); try { m.setup(); } catch (Exception e) { throw new Exception("Failed to call #setup() for module: " + m, e); } } return injector; }
From source file:org.icgc.dcc.portal.pql.convert.Jql2PqlConverter.java
private static ObjectMapper registerJqlDeserializer(ObjectMapper mapper) { val module = new SimpleModule(); module.addDeserializer(JqlFilters.class, new JqlFiltersDeserializer()); mapper.registerModule(module);// ww w. jav a2s. c o m return mapper; }
From source file:org.deeplearning4j.ui.UiServer.java
private SimpleModule module() { SimpleModule module = new SimpleModule(); module.addSerializer(INDArray.class, new VectorSerializer()); module.addDeserializer(INDArray.class, new VectorDeSerializer()); return module; }