List of usage examples for com.fasterxml.jackson.databind ObjectMapper setDateFormat
public ObjectMapper setDateFormat(DateFormat dateFormat)
From source file:org.springframework.cloud.dataflow.server.config.web.WebConfiguration.java
private void setupObjectMapper(ObjectMapper objectMapper) { objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); objectMapper.setDateFormat(new ISO8601DateFormatWithMilliSeconds()); objectMapper.addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class); objectMapper.addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class); }
From source file:org.killbill.billing.plugin.avatax.client.AvaTaxClient.java
@Override protected ObjectMapper createObjectMapper() { final ObjectMapper objectMapper = super.createObjectMapper(); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd")); return objectMapper; }
From source file:com.wiiyaya.consumer.web.initializer.config.WebConfig.java
/** * ???//w ww . j av a2 s .com */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(ConfigConstant.SYSTEM_CHARSET); stringConverter.setWriteAcceptCharset(false); converters.add(new ByteArrayHttpMessageConverter()); converters.add(stringConverter); converters.add(new ResourceHttpMessageConverter()); converters.add(new SourceHttpMessageConverter<Source>()); converters.add(new AllEncompassingFormHttpMessageConverter()); converters.add(new Jaxb2RootElementHttpMessageConverter()); MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper om = jacksonConverter.getObjectMapper(); om.setDateFormat(new SimpleDateFormat(ConfigConstant.SYSTEM_DATE_FORMAT)); om.setLocale(ConfigConstant.SYSTEM_LOCALE); om.setTimeZone(TimeZone.getTimeZone(ConfigConstant.SYSTEM_TIME_ZONE)); om.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() { @Override public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeString(StringUtils.EMPTY); } }); om.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true); om.configure(Feature.WRITE_BIGDECIMAL_AS_PLAIN, true); List<MediaType> mediaTypeList = new ArrayList<MediaType>(); mediaTypeList.add(new MediaType("text", "plain", ConfigConstant.SYSTEM_CHARSET)); jacksonConverter.setSupportedMediaTypes(mediaTypeList); converters.add(jacksonConverter); }
From source file:cz.muni.fi.pa165.rest.layer.RootWebContext.java
@Bean @Primary//from w w w .ja va 2 s. co m public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter() { MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH)); objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION); jsonConverter.setObjectMapper(objectMapper); return jsonConverter; }
From source file:com.iflytek.edu.cloud.frame.spring.MappingJackson2HttpMessageConverterExt.java
public MappingJackson2HttpMessageConverterExt() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); objectMapper.setDateFormat(dateFormat); this.setObjectMapper(objectMapper); }
From source file:de.brendamour.jpasskit.signing.PKAbstractSIgningUtil.java
protected ObjectWriter configureObjectMapper(final ObjectMapper jsonObjectMapper) { jsonObjectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); jsonObjectMapper.setDateFormat(new ISO8601DateFormat()); SimpleFilterProvider filters = new SimpleFilterProvider(); // haven't found out, how to stack filters. Copying the validation one for now. filters.addFilter("validateFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors")); filters.addFilter("pkPassFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors", "foregroundColorAsObject", "backgroundColorAsObject", "labelColorAsObject", "passThatWasSet")); filters.addFilter("barcodeFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors", "messageEncodingAsString")); filters.addFilter("charsetFilter", SimpleBeanPropertyFilter.filterOutAllExcept("name")); jsonObjectMapper.setSerializationInclusion(Include.NON_NULL); jsonObjectMapper.addMixIn(Object.class, ValidateFilterMixIn.class); jsonObjectMapper.addMixIn(PKPass.class, PkPassFilterMixIn.class); jsonObjectMapper.addMixIn(PKBarcode.class, BarcodeFilterMixIn.class); jsonObjectMapper.addMixIn(Charset.class, CharsetFilterMixIn.class); return jsonObjectMapper.writer(filters); }
From source file:io.gumga.security.WebConfigForTest.java
private MappingJackson2HttpMessageConverter jacksonConverter() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Hibernate4Module()); mapper.registerModule(new JodaModule()); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.setDateFormat(new ISO8601DateFormat()); mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); jacksonConverter.setObjectMapper(mapper); return jacksonConverter; }
From source file:org.geoserver.notification.geonode.GeoNodeJsonEncoder.java
@Override public byte[] encode(Notification notification) throws Exception { byte[] ret = null; ObjectMapper mapper = new ObjectMapper(); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")); mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); mapper.setSerializationInclusion(Include.NON_NULL); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); KombuMessage message = new KombuMessage(); message.setId(new UID().toString()); message.setType(notification.getType() != null ? notification.getType().name() : null); message.setAction(notification.getAction() != null ? notification.getAction().name() : null); message.setTimestamp(new Date()); message.setUser(notification.getUser()); message.setOriginator(InetAddress.getLocalHost().getHostAddress()); message.setProperties(notification.getProperties()); if (notification.getObject() instanceof NamespaceInfo) { NamespaceInfo obj = (NamespaceInfo) notification.getObject(); KombuNamespaceInfo source = new KombuNamespaceInfo(); source.setId(obj.getId());/* w w w. j a v a 2s . co m*/ source.setType("NamespaceInfo"); source.setName(obj.getName()); source.setNamespaceURI(obj.getURI()); message.setSource(source); } if (notification.getObject() instanceof WorkspaceInfo) { WorkspaceInfo obj = (WorkspaceInfo) notification.getObject(); KombuWorkspaceInfo source = new KombuWorkspaceInfo(); source.setId(obj.getId()); source.setType("WorkspaceInfo"); source.setName(obj.getName()); source.setNamespaceURI(""); message.setSource(source); } if (notification.getObject() instanceof LayerInfo) { LayerInfo obj = (LayerInfo) notification.getObject(); KombuLayerInfo source = new KombuLayerInfo(); source.setId(obj.getId()); source.setType("LayerInfo"); source.setName(obj.getName()); source.setResourceType(obj.getType() != null ? obj.getType().name() : ""); BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer("name"); Collection<String> styleNames = CollectionUtils.collect(obj.getStyles(), transformer); source.setStyles(StringUtils.join(styleNames.toArray())); source.setDefaultStyle(obj.getDefaultStyle() != null ? obj.getDefaultStyle().getName() : ""); ResourceInfo res = obj.getResource(); source.setWorkspace(res.getStore() != null ? res.getStore().getWorkspace() != null ? res.getStore().getWorkspace().getName() : "" : ""); if (res.getNativeBoundingBox() != null) { source.setBounds(new Bounds(res.getNativeBoundingBox())); } if (res.getLatLonBoundingBox() != null) { source.setGeographicBunds(new Bounds(res.getLatLonBoundingBox())); } message.setSource(source); } if (notification.getObject() instanceof LayerGroupInfo) { LayerGroupInfo obj = (LayerGroupInfo) notification.getObject(); KombuLayerGroupInfo source = new KombuLayerGroupInfo(); source.setId(obj.getId()); source.setType("LayerGroupInfo"); source.setName(obj.getName()); source.setWorkspace(obj.getWorkspace() != null ? obj.getWorkspace().getName() : ""); source.setMode(obj.getType().name()); String rootStyle = obj.getRootLayerStyle() != null ? obj.getRootLayerStyle().getName() : ""; source.setRootLayerStyle(rootStyle); source.setRootLayer(obj.getRootLayer() != null ? obj.getRootLayer().getPath() : ""); for (PublishedInfo pl : obj.getLayers()) { KombuLayerSimpleInfo kl = new KombuLayerSimpleInfo(); if (pl instanceof LayerInfo) { LayerInfo li = (LayerInfo) pl; kl.setName(li.getName()); String lstyle = li.getDefaultStyle() != null ? li.getDefaultStyle().getName() : ""; if (!lstyle.equals(rootStyle)) { kl.setStyle(lstyle); } source.addLayer(kl); } } message.setSource(source); } if (notification.getObject() instanceof ResourceInfo) { ResourceInfo obj = (ResourceInfo) notification.getObject(); KombuResourceInfo source = null; if (notification.getObject() instanceof FeatureTypeInfo) { source = new KombuFeatureTypeInfo(); source.setType("FeatureTypeInfo"); } if (notification.getObject() instanceof CoverageInfo) { source = new KombuCoverageInfo(); source.setType("CoverageInfo"); } if (notification.getObject() instanceof WMSLayerInfo) { source = new KombuWMSLayerInfo(); source.setType("WMSLayerInfo"); } if (source != null) { source.setId(obj.getId()); source.setName(obj.getName()); source.setWorkspace(obj.getStore() != null ? obj.getStore().getWorkspace() != null ? obj.getStore().getWorkspace().getName() : "" : ""); source.setNativeName(obj.getNativeName()); source.setStore(obj.getStore() != null ? obj.getStore().getName() : ""); if (obj.getNativeBoundingBox() != null) { source.setGeographicBunds(new Bounds(obj.getNativeBoundingBox())); } if (obj.boundingBox() != null) { source.setBounds(new Bounds(obj.boundingBox())); } } message.setSource(source); } if (notification.getObject() instanceof StoreInfo) { StoreInfo obj = (StoreInfo) notification.getObject(); KombuStoreInfo source = new KombuStoreInfo(); source.setId(obj.getId()); source.setType("StoreInfo"); source.setName(obj.getName()); source.setWorkspace(obj.getWorkspace() != null ? obj.getWorkspace().getName() : ""); message.setSource(source); } ret = mapper.writeValueAsBytes(message); return ret; }
From source file:de.fhg.fokus.odp.registry.ckan.ODRClientImpl.java
public static <T> JsonNode convert(T obj) { ObjectMapper m = new ObjectMapper(); m.setDateFormat(new SimpleDateFormat(JSON_DATETIME_PATTERN)); JsonNode node = m.valueToTree(obj);/* w w w .j av a 2 s. c o m*/ return node; }