mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'feature/RM-6386_LocalDateDateTime_de_serialization' into 'master'
RM-6386 LocalDate DateTime deserialisation serialisation of joda DateTime,LocalDate types See merge request records-management/records-management!1046
This commit is contained in:
@@ -7,5 +7,4 @@ module.aliases=org_alfresco_module_dod5015
|
||||
module.title=Records Management
|
||||
module.description=Alfresco Record Management Extension
|
||||
module.version=${rm.module.version}
|
||||
|
||||
module.repo.version.min=6.0
|
||||
module.repo.version.min=${rm.module.repo.version.min}
|
@@ -215,4 +215,20 @@
|
||||
<property name="beanName" value="simpleMappingExceptionResolverParent"/>
|
||||
<property name="extendingBeanName" value="rm.simpleMappingExceptionResolver"/>
|
||||
</bean>
|
||||
|
||||
<!-- Extend restJsonModule to include the custom serializers for formatting the LocalDate and DateTime from
|
||||
joda-->
|
||||
<bean id="rm.restJsonModule" parent="restJsonModule">
|
||||
<property name="jsonSerializers">
|
||||
<list merge="true">
|
||||
<bean class="org.alfresco.rm.rest.api.util.CustomLocalDateSerializer" />
|
||||
<bean class="org.alfresco.rm.rest.api.util.CustomDateTimeSerializer" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.util.BeanExtender">
|
||||
<property name="beanName" value="restJsonModule" />
|
||||
<property name="extendingBeanName" value="rm.restJsonModule" />
|
||||
</bean>
|
||||
</beans>
|
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rm.rest.api.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Custom Date Time serializer for formatting org.joda.time.DateTime
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 3.0
|
||||
*/
|
||||
public class CustomDateTimeSerializer extends StdSerializer<DateTime>
|
||||
{
|
||||
/** Date time format */
|
||||
private final static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
public CustomDateTimeSerializer()
|
||||
{
|
||||
super(DateTime.class);
|
||||
}
|
||||
|
||||
protected CustomDateTimeSerializer(Class<DateTime> t)
|
||||
{
|
||||
super(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom serialize method to convert the org.joda.time.DateTime into string value using the DATE_TIME_FORMAT
|
||||
*
|
||||
* @param value datetime value
|
||||
* @param jgen
|
||||
* @param provider
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException
|
||||
{
|
||||
jgen.writeString(DATE_TIME_FORMAT.print(value));
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rm.rest.api.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Custom Local Date serializer for formatting org.joda.time.LocalDate
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 3.0
|
||||
*/
|
||||
public class CustomLocalDateSerializer extends StdSerializer<LocalDate>
|
||||
{
|
||||
/** Local date format */
|
||||
private final static DateTimeFormatter DATE_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd");
|
||||
|
||||
public CustomLocalDateSerializer()
|
||||
{
|
||||
super(LocalDate.class);
|
||||
}
|
||||
|
||||
protected CustomLocalDateSerializer(Class<LocalDate> t)
|
||||
{
|
||||
super(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom serialize method to convert the org.joda.time.LocalDate into string value using the DATE_FORMAT
|
||||
*
|
||||
* @param value local date value
|
||||
* @param jgen
|
||||
* @param provider
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider provider) throws IOException
|
||||
{
|
||||
jgen.writeString(DATE_FORMAT.print(value));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user