Class KiwiJacksonDataFormats
NOTE: This relies entirely on jackson's data format detection!!! You will also need to ensure that the jackson-core, jackson-dataformat-xml, jackson-dataformat-yaml dependencies are present at runtime.
WARNING: Before using, please make sure you understand how Jackson actually does its detection. Hint: it's not
magic, and may not be as robust as you might like. For example, the YAML detector will only report YAML if the
content starts with the formal YAML preamble "---". Use the "@see" links below for links to the various Jackson
classes that perform data format detection. The main class is DataFormatDetector, to which you supply
one or more detectors, which are JsonFactory and its subclasses.
- See Also:
-
DataFormatDetectorJsonFactoryXmlFactoryYAMLFactoryCharset.defaultCharset()
-
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<JacksonDataFormat>detectFormat(String text) Detect the data format of given text using the defaultCharset.static Optional<JacksonDataFormat>detectFormat(String text, Charset charset) Detect the data format of given text using the givenCharset.detectFormat(String text, Charset charset, com.fasterxml.jackson.core.format.DataFormatDetector detector) Detect the data format of given text using givenCharsetandDataFormatDetector.static Optional<JacksonDataFormat>detectFormatUtf8(String text) Detect the data format of given text using UTF-8Charset.static booleanisFormat(JacksonDataFormat matchFormat, String text, Charset charset) Does the given text, using the givenCharset, have data formatmatchFormat.static booleanIs the given text JSON using the defaultCharset?static booleanIs the given text JSON using the givenCharset?static booleanisJsonUtf8(String text) Is the given text JSON using UTF-8Charset?static booleanIs the given text XML using the defaultCharset?static booleanIs the given text XML using the givenCharset?static booleanIs the given text XML using UTF-8Charset?static booleanIs the given text YAML using the defaultCharset?static booleanIs the given text YAML using the givenCharset?static booleanisYamlUtf8(String text) Is the given text YAML using UTF-8Charset?
-
Method Details
-
isJson
Is the given text JSON using the defaultCharset?- Parameters:
text- the String value to check- Returns:
trueiftextis JSON;falseotherwise
-
isJsonUtf8
Is the given text JSON using UTF-8Charset?- Parameters:
text- the String value to check- Returns:
trueiftextis JSON;falseotherwise
-
isJson
Is the given text JSON using the givenCharset?- Parameters:
text- the String value to checkcharset- the character set to use- Returns:
trueiftextis JSON;falseotherwise
-
isXml
Is the given text XML using the defaultCharset?- Parameters:
text- the String value to check- Returns:
trueiftextis XML;falseotherwise
-
isXmlUtf8
Is the given text XML using UTF-8Charset?- Parameters:
text- the String value to check- Returns:
trueiftextis XML;falseotherwise
-
isXml
Is the given text XML using the givenCharset?- Parameters:
text- the String value to checkcharset- the character set to use- Returns:
trueiftextis XML;falseotherwise
-
isYaml
Is the given text YAML using the defaultCharset?- Parameters:
text- the String value to check- Returns:
trueiftextis YAML;falseotherwise- Implementation Note:
- Jackson does NOT consider the content YAML without "---" at the top of the file!
-
isYamlUtf8
Is the given text YAML using UTF-8Charset?- Parameters:
text- the String value to check- Returns:
trueiftextis YAML;falseotherwise- Implementation Note:
- Jackson does NOT consider the content YAML without "---" at the top of the file!
-
isYaml
Is the given text YAML using the givenCharset?- Parameters:
text- the String value to checkcharset- the character set to use- Returns:
trueiftextis YAML;falseotherwise- Implementation Note:
- Jackson does NOT consider the content YAML without "---" at the top of the file!
-
isFormat
Does the given text, using the givenCharset, have data formatmatchFormat.- Parameters:
matchFormat- the format to match againsttext- the String value to checkcharset- the character set to use- Returns:
trueiftextis equal tomatchFormat;falseotherwise
-
detectFormat
Detect the data format of given text using the defaultCharset.- Parameters:
text- the String value to check- Returns:
- Optional containing detected format, or empty Optional if format was not detected or not supported
-
detectFormatUtf8
Detect the data format of given text using UTF-8Charset.- Parameters:
text- the String value to check- Returns:
- Optional containing detected format, or empty Optional if format was not detected or not supported
-
detectFormat
Detect the data format of given text using the givenCharset.- Parameters:
text- the String value to checkcharset- the character set to use- Returns:
- Optional containing detected format, or empty Optional if format was not detected or not supported
-
detectFormat
public static Optional<String> detectFormat(String text, Charset charset, com.fasterxml.jackson.core.format.DataFormatDetector detector) Detect the data format of given text using givenCharsetandDataFormatDetector.This method is an "escape hatch"; it allows detection of formats not supported in
JacksonDataFormatsince it accepts aDataFormatDetectorand it returns a String. Since the caller supplies its own customDataFormatDetector, that caller dictates the formats that are supported. And because it returns a String, it is not limited to the formats defined in theJacksonDataFormatenum.- Parameters:
text- the String value to checkcharset- the character set to usedetector- the format detector to use- Returns:
- Optional containing detected format name, or empty Optional if format was not
detected or not supported by the supplied
DataFormatDetector
-