Skip to content

Commit

Permalink
Fix 2.0 for Bug 404069 - MOXy should not append .0 to time info for …
Browse files Browse the repository at this point in the history
…dateTime and time formats + unit test (#1403)

This new feature optionally add suffix/decimal part to time part/seconds in case of conversion from supported date/time formats into String. This suffix is controlled by new "org.eclipse.persistence.xml.time.suffix" system property.
It happens only if source time doesn't contain fraction of seconds and for XML, JSON conversion. E.g.:
For -Dorg.eclipse.persistence.xml.time.suffix=.0
Source value: 2003-08-29T03:00:00-04:00 -> Output string: 2003-08-29T03:00:00.0-04:00
Source value: 1975-02-21T07:47:15 -> Output string: 1975-02-21T07:47:15.0

In case of fraction of seconds in the input behavior is still same e.g.:
Source value: 1975-02-21T07:47:15.123 -> Output string: 1975-02-21T07:47:15.123

It simplifies migration from WebLogic Server 11g to 12c.
Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
  • Loading branch information
rfelcman committed Jan 24, 2022
1 parent adf28f4 commit 1bef069
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 37 deletions.
40 changes: 39 additions & 1 deletion foundation/org.eclipse.persistence.core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -368,6 +368,10 @@
<includes>
<include>org.eclipse.persistence.testing.oxm.OXMSRGTestSuite</include>
</includes>
<excludes>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesNonDefaultTestCases</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.DateAndTimeNonDefaultTestCases</exclude>
</excludes>
</configuration>
</execution>
<execution>
Expand All @@ -394,6 +398,7 @@
<include>*.MappingClassLoaderTestCases</include>
<include>org.eclipse.persistence.testing.oxm.mappings.directcollection.nillable.DirectCollectionMappingNillableTestSuite</include>
<include>org.eclipse.persistence.testing.oxm.mappings.keybased.multipletargets.compositekey.CompositeKeyTestCases</include>
<include>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesTestCases</include>
</includes>
<excludes>
<exclude>*.MappingTestSuite</exclude>
Expand All @@ -402,6 +407,8 @@
<exclude>org.eclipse.persistence.testing.oxm.mappings.DocPresMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.anyobjectandanycollection.XMLAnyObjectAndAnyCollectionMappingTestSuite</exclude>
<exclude>*.SAXMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesNonDefaultTestCases</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.DateAndTimeNonDefaultTestCases</exclude>
</excludes>
</configuration>
</execution>
Expand Down Expand Up @@ -436,6 +443,8 @@
<exclude>org.eclipse.persistence.testing.oxm.mappings.anyobjectandanycollection.XMLAnyObjectAndAnyCollectionMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.keybased.compositekeyclass.CompositeKeyClassMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.sequenced.SequencedMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesNonDefaultTestCases</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.DateAndTimeNonDefaultTestCases</exclude>
</excludes>
</configuration>
</execution>
Expand Down Expand Up @@ -482,6 +491,8 @@
<exclude>org.eclipse.persistence.testing.oxm.mappings.compositeobject.self.converter.CompositeObjectSelfConverterTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.keybased.compositekeyclass.CompositeKeyClassMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.containeracessor.ContainerAccessorTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesNonDefaultTestCases</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.DateAndTimeNonDefaultTestCases</exclude>
</excludes>
</configuration>
</execution>
Expand Down Expand Up @@ -529,6 +540,8 @@
<exclude>org.eclipse.persistence.testing.oxm.mappings.compositeobject.self.converter.CompositeObjectSelfConverterTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.keybased.compositekeyclass.CompositeKeyClassMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.containeracessor.ContainerAccessorTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesNonDefaultTestCases</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.DateAndTimeNonDefaultTestCases</exclude>
</excludes>
</configuration>
</execution>
Expand Down Expand Up @@ -565,9 +578,34 @@
<exclude>org.eclipse.persistence.testing.oxm.mappings.keybased.KeyBasedMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.keybased.compositekeyclass.CompositeKeyClassMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.mappings.sequenced.SequencedMappingTestSuite</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesNonDefaultTestCases</exclude>
<exclude>org.eclipse.persistence.testing.oxm.systemproperties.DateAndTimeNonDefaultTestCases</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>test-oxm-non-default-system-properties</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skipTests>${test-skip-oxm}</skipTests>
<reportNameSuffix>test-oxm-non-default-system-properties</reportNameSuffix>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<systemPropertyVariables>
<org.eclipse.persistence.json.type-compatibility>true</org.eclipse.persistence.json.type-compatibility>
<org.eclipse.persistence.json.use-xsd-types-prefix>true</org.eclipse.persistence.json.use-xsd-types-prefix>
<org.eclipse.persistence.json.type-attribute-name>jsonTestType</org.eclipse.persistence.json.type-attribute-name>
<org.eclipse.persistence.json.disable-nested-array-name>true</org.eclipse.persistence.json.disable-nested-array-name>
<org.eclipse.persistence.xml.time.suffix>.0</org.eclipse.persistence.xml.time.suffix>
</systemPropertyVariables>
<includes>
<include>org.eclipse.persistence.testing.oxm.systemproperties.OXMSystemPropertiesNonDefaultTestCases</include>
<include>org.eclipse.persistence.testing.oxm.systemproperties.DateAndTimeNonDefaultTestCases</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -54,6 +54,20 @@ public final class OXMSystemProperties {

public static final String DISABLE_SECURE_PROCESSING = "eclipselink.disableXmlSecurity";

/**
* Add suffix/decimal part to time part/seconds in case of conversion from supported date/time formats into String.
* It happens only if source time doesn't contain fraction of seconds and for XML, JSON conversion. E.g.:
* For -Dorg.eclipse.persistence.xml.time.suffix=.0
* <ul>
* <li>Source value: 2003-08-29T03:00:00-04:00 -&gt; Output string: 2003-08-29T03:00:00.0-04:00</li>
* <li>Source value: 1975-02-21T07:47:15 -&gt; Output string: 1975-02-21T07:47:15.0</li>
* </ul>
* @since 2.7.11
*/
public static final String XML_CONVERSION_TIME_SUFFIX = "org.eclipse.persistence.xml.time.suffix";

public static final String DEFAULT_XML_CONVERSION_TIME_SUFFIX = "";

public static final Boolean jsonTypeCompatiblity = PrivilegedAccessHelper.getSystemPropertyBoolean(JSON_TYPE_COMPATIBILITY, false);

public static final Boolean jsonUseXsdTypesPrefix = PrivilegedAccessHelper.getSystemPropertyBoolean(JSON_USE_XSD_TYPES_PREFIX, false);
Expand All @@ -62,6 +76,8 @@ public final class OXMSystemProperties {

public static final Boolean jsonDisableNestedArrayName = PrivilegedAccessHelper.getSystemPropertyBoolean(JSON_DISABLE_NESTED_ARRAY_NAME, false);

public static final String xmlConversionTimeSuffix = PrivilegedAccessHelper.getSystemProperty(XML_CONVERSION_TIME_SUFFIX, DEFAULT_XML_CONVERSION_TIME_SUFFIX);

private OXMSystemProperties() {}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -1166,7 +1166,7 @@ private String truncateMillis(String xmlFormat) {
milliStr = '.' + milliStr;
result = pre + milliStr + post;
} else {
result = pre + post;
result = pre + OXMSystemProperties.xmlConversionTimeSuffix + post;
}
}
return result;
Expand Down Expand Up @@ -1873,7 +1873,7 @@ public Object clone() {
private String appendNanos(String string, Timestamp ts) {
StringBuilder strBldr = new StringBuilder(string);
int nanos = ts.getNanos();
strBldr.append(nanos==0 ? "" : '.' + Helper.buildZeroPrefixAndTruncTrailZeros(nanos, TOTAL_NS_DIGITS));
strBldr.append(nanos==0 ? OXMSystemProperties.xmlConversionTimeSuffix : '.' + Helper.buildZeroPrefixAndTruncTrailZeros(nanos, TOTAL_NS_DIGITS));
return strBldr.toString();
}

Expand All @@ -1889,7 +1889,7 @@ private String appendMillis(String string, long time) {
// adjust for negative time values, i.e. before Epoch
msns = msns + 1000;
}
strBldr.append(msns==0 ? "" : '.' + Helper.buildZeroPrefixAndTruncTrailZeros(msns, TOTAL_MS_DIGITS));
strBldr.append(msns==0 ? OXMSystemProperties.xmlConversionTimeSuffix : '.' + Helper.buildZeroPrefixAndTruncTrailZeros(msns, TOTAL_MS_DIGITS));
return strBldr.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.testing.oxm.systemproperties;


import org.eclipse.persistence.testing.oxm.xmlconversionmanager.DateAndTimeTestCases;

public class DateAndTimeNonDefaultTestCases extends DateAndTimeTestCases {

public DateAndTimeNonDefaultTestCases(String name) {
super(name);
super.controlXmlConversionTimeSuffix = ".0";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Oracle - initial API and implementation
package org.eclipse.persistence.testing.oxm.systemproperties;

import org.eclipse.persistence.internal.oxm.OXMSystemProperties;
import org.eclipse.persistence.internal.oxm.XMLConversionManager;
import org.eclipse.persistence.oxm.XMLConstants;
import org.junit.Test;

import java.sql.Timestamp;
import java.util.TimeZone;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* Tests OXMSystemProperties class. With default non-values. It requires to be isolated JVM to avoid impact to others tests or it should be executed with other tests with same system properties.
*/
public class OXMSystemPropertiesNonDefaultTestCases {

static {
System.setProperty(OXMSystemProperties.JSON_TYPE_COMPATIBILITY, "true");
System.setProperty(OXMSystemProperties.JSON_USE_XSD_TYPES_PREFIX, "true");
System.setProperty(OXMSystemProperties.JSON_TYPE_ATTRIBUTE_NAME, "jsonTestType");
System.setProperty(OXMSystemProperties.JSON_DISABLE_NESTED_ARRAY_NAME, "true");
System.setProperty(OXMSystemProperties.XML_CONVERSION_TIME_SUFFIX, ".0");
}


@Test
public void testNonDefaultProperties() {
assertTrue(OXMSystemProperties.jsonTypeCompatiblity);
assertTrue(OXMSystemProperties.jsonUseXsdTypesPrefix);
assertEquals("jsonTestType", OXMSystemProperties.jsonTypeAttributeName);
assertTrue(OXMSystemProperties.jsonDisableNestedArrayName);
assertEquals(".0", OXMSystemProperties.xmlConversionTimeSuffix);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Oracle - initial API and implementation
package org.eclipse.persistence.testing.oxm.systemproperties;

import org.eclipse.persistence.internal.oxm.OXMSystemProperties;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

/**
* Tests OXMSystemProperties class. With default values.
*/
public class OXMSystemPropertiesTestCases {

@Test
public void testProperties() {
assertFalse(OXMSystemProperties.jsonTypeCompatiblity);
assertFalse(OXMSystemProperties.jsonUseXsdTypesPrefix);
assertEquals("type", OXMSystemProperties.jsonTypeAttributeName);
assertFalse(OXMSystemProperties.jsonDisableNestedArrayName);
assertEquals("", OXMSystemProperties.xmlConversionTimeSuffix);
}
}

0 comments on commit 1bef069

Please sign in to comment.