jenetics / jpx

JPX - Java GPX library
Apache License 2.0
206 stars 31 forks source link

Elevation serialization for values > 1000m is incompatible with deserialization #162

Closed raynigon closed 2 years ago

raynigon commented 2 years ago

Issue description

I currently use the library to serialize and deserialize GPX for analysis. Some files contain elevation values greater than 1000m. For these files the elevation is serialized with a comma as "thousand separator". When the serialized GPX data is deserialized, Double.parseDouble is used, which does not support the given Syntax.

Steps to reproduce the issue

  1. Generate a GPX object with at least one waypoint which has an elevation greater 1000m
  2. Serialze the object with the GPX.Writer#write method
  3. Deserialize the object with the GPX.Reader#read method

What's the expected result?

What's the actual result?

Additional details

Code
GPX gpx = GPX.builder()
        .addWayPoint { wp ->
            wp.ele(1234.5).build(1.2, 3.4)
        }
        .build()
String gpxString = GPX.Writer.DEFAULT.toString(gpx)
GPX result = GPX.Reader.DEFAULT.fromString(gpxString)
Stacktrace
java.io.InvalidObjectException: Invalid GPX: Invalid value for 'ele': For input string: "1,234.5"
    at io.jenetics.jpx.GPX$Reader.read(GPX.java:1183)
    at io.jenetics.jpx.GPX$Reader.read(GPX.java:1209)
    at io.jenetics.jpx.GPX$Reader.fromString(GPX.java:1271)