我在对象数组内传递日期参数作为请求参数,同时使用"gatherOnce"
对我的spring容器进行rest调用。
代码如下:
RestTemplate
当请求到达我的服务器时,我收到的日期已久。如何获取日期作为日期?为什么会持续这么长时间?
下面是我的dispatcher-servlet.xml
HttpEntity<SimplePipeServiceRequest> request = new HttpEntity<>(new Object[]{new Date(), 1}, headers);
response = template.postForEntity(uri1, request, String.class);
以及以下是我在进行其余调用的地方的dispatcher-servlet.xml
<context:component-scan base-package="com.altra.aligne.controller"></context:component-scan>
<mvc:annotation-driven conversion-service="conversionService">
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.altra.middleware.spring.CustomObjectMapper"></bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- RequestMappingHandlerMapping.setUseSuffixPatternMatch(boolean useSuffixPatternMatch) = Whether to use suffix pattern match (".*")
when matching patterns to requests. -->
<bean class="com.altra.middleware.spring.ControllerBeanPostProcessor" />
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="com.altra.middleware.spring.GenericDTOConverter"/>
<bean class="com.altra.middleware.spring.StringToDateConverter"/>
</list>
</property>
</bean>
任何人都可以解释将日期转换为长日期的位置和方式,如果我想避免将日期转换为长日期,以及是否可以从长日期再次获得相等的日期?
我不了解杰克逊在Spring中的实际工作方式。
编辑
<mvc:annotation-driven>
<mvc:message-converters>
<!-- We configure the Jackson mapper to output dates in ISO801 format. This requires adding our
customized Jackson mapper to the list of Spring MVC message converters. But, if we just add our bean here
all by itself, it will handle requests it should not handle, e.g. encoding strings. So we need to add the
other standard message converters here too, and make sure to put the customized Jackson converter AFTER the
string converter. -->
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<ref bean="acmJacksonConverter"/>
<bean class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/>
<!-- atom feed requires com.sun.syndication package ... -->
<!--<bean class="org.springframework.http.converter.feed.AtomFeedHttpMessageConverter"/>-->
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
<bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2CollectionHttpMessageConverter"/>
<!-- marshalling converter requires spring oxm -->
<!--<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"/>-->
</mvc:message-converters>
</mvc:annotation-driven>
不过,执行 post 后,两个序列化程序都不会被调用。
谢谢!
答案 0 :(得分:0)
您需要自定义ObjectMapper
:
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(DateFormat.getDateInstance());
mapper.setTimeZone(TimeZone.getTimeZone("UTC"));
但是,如果可以的话,使用Java 8
Time
软件包会更安全。
有关更多信息,请查看: