![JAR search and dependency download from the Maven repository](/logo.png)
org.entur.siri.adapter.DurationXmlAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of siri-java-model Show documentation
Show all versions of siri-java-model Show documentation
Java objects based on the public SIRI XSDs
The newest version!
package org.entur.siri.adapter;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import java.time.Duration;
public class DurationXmlAdapter extends XmlAdapter {
@Override
public Duration unmarshal(String stringValue) {
return stringValue != null ? Duration.parse(stringValue) : null;
}
/**
* XML datatype xs:duration is only partially based on ISO-8601, and differs when it comes to negative durations.
*
* While ISO-8601 allows for negative values for each part of the duration (e.g. PT-1M-30S
), an xs:duration only
* allows the entire duration to be negative - i.e. -PT1M30S
*
* This method rewrites the produced Duration-string to produce a valid xs:duration
*
* @param duration
* @return
*/
@Override
public String marshal(Duration duration) {
if (duration != null) {
if (duration.isNegative()) {
StringBuilder xmlDurationStr = new StringBuilder();
xmlDurationStr.append("-");
xmlDurationStr.append(
duration.toString().replaceAll("-", "")
);
return xmlDurationStr.toString();
} else {
return duration.toString();
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy