-
-
Notifications
You must be signed in to change notification settings - Fork 229
Fix #643: Add ToXmlGenerator.Feature
or allowing XML Schema/JAXB compatible Infinity representation
#644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cowtowncoder
merged 2 commits into
FasterXML:2.17
from
ahcodedthat:xml-schema-float-infinity
Mar 13, 2024
Merged
Fix #643: Add ToXmlGenerator.Feature
or allowing XML Schema/JAXB compatible Infinity representation
#644
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import com.fasterxml.jackson.core.json.JsonWriteContext; | ||
import com.fasterxml.jackson.core.util.JacksonFeatureSet; | ||
import com.fasterxml.jackson.dataformat.xml.XmlPrettyPrinter; | ||
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser; | ||
import com.fasterxml.jackson.dataformat.xml.util.DefaultXmlPrettyPrinter; | ||
import com.fasterxml.jackson.dataformat.xml.util.StaxUtil; | ||
|
||
|
@@ -106,6 +107,34 @@ public enum Feature implements FormatFeature | |
* @since 2.17 | ||
*/ | ||
AUTO_DETECT_XSI_TYPE(false), | ||
|
||
/** | ||
* Feature that determines how floating-point infinity values are | ||
* serialized. | ||
*<p> | ||
* By default, {@link Float#POSITIVE_INFINITY} and | ||
* {@link Double#POSITIVE_INFINITY} are serialized as {@code Infinity}, | ||
* and {@link Float#NEGATIVE_INFINITY} and | ||
* {@link Double#NEGATIVE_INFINITY} are serialized as | ||
* {@code -Infinity}. This is the representation that Java normally | ||
* uses for these values (see {@link Float#toString(float)} and | ||
* {@link Double#toString(double)}), but JAXB and other XML | ||
* Schema-conforming readers won't understand it. | ||
*<p> | ||
* With this feature enabled, these values are instead serialized as | ||
* {@code INF} and {@code -INF}, respectively. This is the | ||
* representation that XML Schema and JAXB use (see the XML Schema | ||
* primitive types | ||
* <a href="https://www.w3.org/TR/xmlschema-2/#float"><code>float</code></a> | ||
* and | ||
* <a href="https://www.w3.org/TR/xmlschema-2/#double"><code>double</code></a>). | ||
*<p> | ||
* When deserializing, Jackson always understands both representations, | ||
* so there is no corresponding {@link FromXmlParser.Feature}. | ||
*<p> | ||
* Feature is disabled by default for backwards compatibility. | ||
*/ | ||
XML_SCHEMA_CONFORMING_FLOATS(false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty good but maybe add |
||
; | ||
|
||
final boolean _defaultState; | ||
|
@@ -1174,6 +1203,11 @@ public void writeNumber(long l) throws IOException | |
@Override | ||
public void writeNumber(double d) throws IOException | ||
{ | ||
if (Double.isInfinite(d) && isEnabled(Feature.XML_SCHEMA_CONFORMING_FLOATS)) { | ||
writeNumber(d > 0d ? "INF" : "-INF"); | ||
return; | ||
} | ||
|
||
_verifyValueWrite("write number"); | ||
if (_nextName == null) { | ||
handleMissingName(); | ||
|
@@ -1202,6 +1236,11 @@ public void writeNumber(double d) throws IOException | |
@Override | ||
public void writeNumber(float f) throws IOException | ||
{ | ||
if (Float.isInfinite(f) && isEnabled(Feature.XML_SCHEMA_CONFORMING_FLOATS)) { | ||
writeNumber(f > 0f ? "INF" : "-INF"); | ||
return; | ||
} | ||
|
||
_verifyValueWrite("write number"); | ||
if (_nextName == null) { | ||
handleMissingName(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.