Skip to content

Commit

Permalink
fixup! fix: use appropriate methods to convert the numbers in XML
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelaepure10 committed Jun 5, 2024
1 parent 979ce54 commit af96e9e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<xs:element name="longNumber" type="xs:long" minOccurs="0"/>
<xs:element name="floatNumber" type="xs:float" minOccurs="0"/>
<xs:element name="shortNumber" type="xs:short" minOccurs="0"/>

<element name="doubleSimpleNumber" type="double" minOccurs="0"/>
</sequence>
</extension>
</complexContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,20 @@ class StreamGmlWriter2Test {

@Test
void testNumbers() throws Exception {
// testNumber("doubleSimpleNumber", 123456789.123456789)

testNumber("integerNumber", 12345)
testNumber("doubleNumber", 12345.123456789)
testNumber("floatNumber", 12345.6789F)
testNumber("longNumber", 1234567890123456789L)
testNumber("shortNumber", 12345 as short)
testNumber("decimalNumber", new BigDecimal("1234567890.123456789"))

double doubleNumber = 123456789.123456789
testNumber("decimalNumber", new BigDecimal(doubleNumber));

doubleNumber = 1.23456789123456789E8
testNumber("decimalNumber", new BigDecimal(doubleNumber));
}

void testNumber(String elementName, number) throws Exception {
Expand All @@ -403,10 +411,18 @@ class StreamGmlWriter2Test {

// Write file, validate and load it
def writer = new GmlInstanceWriter()
def xmlFile = writeFile(instance, schema, writer).getAbsolutePath()
File outFile = writeFile(instance, schema, writer)
def xmlFile = outFile.getAbsolutePath()
def xml = new XmlSlurper().parse(xmlFile)

println number.toString()
println xml.featureMember.PrimitiveTest."$elementName".text()

assertEquals(number.toString(), xml.featureMember.PrimitiveTest."$elementName".text())

if (DEL_TEMP_FILES) {
// outFile.delete()
}
}

@CompileStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ else if (simpleTypeValue instanceof XmlDateTime) {

xmlDateTime.setGDateValue(gdate);
}

// Numbers should be handled here
if (simpleTypeValue != null) {
else if (simpleTypeValue != null && simpleTypeValue instanceof XmlAnySimpleType) {
// Numbers should be handled here
return simpleTypeValue.getStringValue();
}
} catch (ConversionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import java.math.BigDecimal;

import org.apache.xmlbeans.XmlDouble;
import org.springframework.core.convert.converter.Converter;

Expand All @@ -31,6 +33,9 @@ public XmlDouble convert(Double value) {
if (value == null) {
return null;
}
if (value.toString().contains("E")) {
value = Double.parseDouble(new BigDecimal(value).toPlainString());
}
return XmlDouble.Factory.newValue(value);
}

Expand Down

0 comments on commit af96e9e

Please sign in to comment.