List of usage examples for com.fasterxml.jackson.databind ObjectMapper registerModule
public ObjectMapper registerModule(Module module)
From source file:com.goodhuddle.huddle.HuddleWebConfig.java
private ObjectMapper objectMapper() { Jackson2ObjectMapperFactoryBean bean = new Jackson2ObjectMapperFactoryBean(); bean.setIndentOutput(true);//from w w w. ja va 2 s . c o m bean.setSimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); bean.afterPropertiesSet(); ObjectMapper objectMapper = bean.getObject(); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objectMapper.registerModule(new JodaModule()); return objectMapper; }
From source file:com.concentricsky.android.khanacademy.data.remote.KAEntityFetcherTask.java
@Override protected T doInBackground(Void... arg0) { // call API and fetch an entity tree (commonly the tree rooted at the root topic) RestTemplate restTemplate = new RestTemplate(); if (consumer != null) { restTemplate.setRequestFactory(new SpringRequestFactory(consumer)); }//from ww w . j a v a 2 s . c om // TODO : Set up stream parsing. // RequestCallback callback = new RequestCallback() { // // public void doWithRequest(ClientHttpRequest request) // throws IOException { // // TODO Auto-generated method stub // // } // // }; // // ResponseExtractor<T> extractor = new ResponseExtractor<T>() { // // public T extractData(ClientHttpResponse response) // throws IOException { // // InputStream stream = response.getBody(); // // // return null; // } // // }; // // restTemplate.execute(url, HttpMethod.GET, requestCallback, responseExtractor) // Provide a converter to the restTemplate to get automagic json --> pojo deserialization. // Provide a mapper to the converter so we can register the custom Video deserializer. Otherwise, the default ObjectMapper would do fine. ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new VideoDeserializerModule()); MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter(); converter.setObjectMapper(mapper); restTemplate.getMessageConverters().add(converter); ModelBase entity = null; try { entity = restTemplate.getForObject(this.url, ModelBase.class); } catch (HttpClientErrorException e) { e.printStackTrace(); exception = e; // meanwhile, entity is null, so we let that return naturally. } catch (ResourceAccessException e) { // This one happens on Nexus 7 if we have set a SpringRequestFactory but get no Auth challenge. // org.springframework.web.client.ResourceAccessException: I/O error: No authentication challenges found; nested exception is java.io.IOException: No authentication challenges found e.printStackTrace(); Log.e(LOG_TAG, "url was " + url); exception = e; } T result; try { result = (T) entity; } catch (ClassCastException e) { e.printStackTrace(); exception = e; result = null; } Log.d(LOG_TAG, "Response received. Returning entity."); return result; }
From source file:ijfx.service.history.HistoryService.java
public boolean saveWorkflow(String path, Workflow workflow) { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new WorkflowMapperModule()); try {/*from w w w. j a v a 2 s. c o m*/ mapper.writeValue(new File(path), workflow); return true; } catch (IOException ex) { ImageJFX.getLogger().log(Level.SEVERE, "Error when saving worflow. It's possible you don't have the permission.", ex); ; } return false; }
From source file:com.btmatthews.atlas.core.dao.mongo.TestMongoDAO.java
@Test public void unmarshal() throws Exception { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new I18NModule()); objectMapper.registerModule(new JSR310Module()); final Person person = objectMapper.readValue( "{\"id\": \"ee749160-c6a0-11e2-8b8b-0800200c9a66\", \"name\": \"Brian Matthews\", \"validFrom\": \"1900-01-01T00:00:00.000\", \"validTo\": \"9999-12-31T23:59:59.999\"}", PersonImpl.class); assertThat(person).isNotNull();/*from w w w . j av a 2 s .c om*/ assertThat(person.getId()).isEqualTo("ee749160-c6a0-11e2-8b8b-0800200c9a66"); assertThat(person.getName()).isEqualTo("Brian Matthews"); }
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 om*/ 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.btmatthews.atlas.core.dao.mongo.TestMongoDAO.java
@Test public void marshal() throws Exception { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new I18NModule()); objectMapper.registerModule(new JSR310Module()); final Person person = new PersonImpl("ee749160-c6a0-11e2-8b8b-0800200c9a66", "Brian Matthews", VALID_FROM, VALID_TO);/*from w w w . ja v a2 s .com*/ final String json = objectMapper.writeValueAsString(person); JsonAssert.with(json).assertThat("$.id", Matchers.equalTo("ee749160-c6a0-11e2-8b8b-0800200c9a66")) .assertThat("$.name", Matchers.equalTo("Brian Matthews")) .assertThat("$.validFrom", Matchers.equalTo("1900-01-01T00:00:00.000")) .assertThat("$.validTo", Matchers.equalTo("9999-12-31T23:59:59.999")); }
From source file:com.sra.biotech.submittool.persistence.client.RestClientConfiguration.java
public MappingJackson2HttpMessageConverter halConverter() { RelProvider defaultRelProvider = defaultRelProvider(); RelProvider annotationRelProvider = annotationRelProvider(); OrderAwarePluginRegistry<RelProvider, Class<?>> relProviderPluginRegistry = OrderAwarePluginRegistry .create(Arrays.asList(defaultRelProvider, annotationRelProvider)); DelegatingRelProvider delegatingRelProvider = new DelegatingRelProvider(relProviderPluginRegistry); ObjectMapper halObjectMapper = new ObjectMapper(); halObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); halObjectMapper.registerModule(new Jackson2HalModule()); halObjectMapper// w ww .j a v a 2s . c o m .setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(delegatingRelProvider, null)); MappingJackson2HttpMessageConverter halConverter = new MappingJackson2HttpMessageConverter(); halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON)); halConverter.setObjectMapper(halObjectMapper); return halConverter; }
From source file:ijfx.service.history.HistoryService.java
public Workflow loadWorkflow(String json) { try {/*from w w w. j ava2s . c o m*/ ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new WorkflowMapperModule()); DefaultWorkflow workflow = mapper.readValue(json, DefaultWorkflow.class); workflow.getStepList().forEach(step -> context.inject(step)); loadWorkflow(workflow); return workflow; } catch (IOException ex) { ImageJFX.getLogger().log(Level.SEVERE, "Error when loading workflow", ex); ; } return null; }
From source file:com.googlecode.wickedcharts.highcharts.jackson.JsonRenderer.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private ObjectMapper createJacksonMapper() { this.jacksonModule.addSerializer(Center.class, new CenterSerializer()); this.jacksonModule.addSerializer(SimpleColor.class, new SimpleColorReferenceSerializer()); this.jacksonModule.addSerializer(HighchartsColor.class, new HighchartsColorReferenceSerializer()); this.jacksonModule.addSerializer(HexColor.class, new HexColorReferenceSerializer()); this.jacksonModule.addSerializer(LowercaseEnum.class, new LowercaseEnumSerializer()); this.jacksonModule.addSerializer(PixelOrPercent.class, new PixelOrPercentSerializer()); this.jacksonModule.addSerializer(Symbol.class, new SymbolSerializer()); this.jacksonModule.addSerializer(RgbaColor.class, new RgbaColorReferenceSerializer()); this.jacksonModule.addSerializer(NullColor.class, new NullColorReferenceSerializer()); this.jacksonModule.addSerializer(MinorTickInterval.class, new MinorTickIntervalSerializer()); this.jacksonModule.addSerializer(Function.class, new FunctionSerializer()); this.jacksonModule.addSerializer(CssStyle.class, new CssStyleSerializer()); this.jacksonModule.addSerializer(DateTimeLabelFormat.class, new DateTimeLabelFormatSerializer()); this.jacksonModule.addSerializer(Coordinate.class, new CoordinateSerializer()); this.jacksonModule.addSerializer(Crosshair.class, new CrosshairSerializer()); this.jacksonModule.addSerializer(RangeCoordinate.class, new RangeCoordinateSerializer()); this.jacksonModule.addSerializer(Bubble.class, new BubbleSerializer()); ObjectMapper mapper = createDefaultObjectMapper(); mapper.setLocale(Locale.ENGLISH); mapper.registerModule(this.jacksonModule); return mapper; }