diff --git a/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/LegacyUimaJsonFormatSupport.java b/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/LegacyUimaJsonFormatSupport.java index 06684d9d259..ef073e48632 100644 --- a/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/LegacyUimaJsonFormatSupport.java +++ b/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/LegacyUimaJsonFormatSupport.java @@ -27,6 +27,7 @@ import de.tudarmstadt.ukp.clarin.webanno.api.format.FormatSupport; import de.tudarmstadt.ukp.clarin.webanno.model.Project; +import de.tudarmstadt.ukp.inception.io.jsoncas.config.LegacyUimaJsonCasFormatProperties; public class LegacyUimaJsonFormatSupport implements FormatSupport @@ -34,6 +35,13 @@ public class LegacyUimaJsonFormatSupport public static final String ID = "json"; public static final String NAME = "UIMA CAS JSON (legacy)"; + private final LegacyUimaJsonCasFormatProperties properties; + + public LegacyUimaJsonFormatSupport(LegacyUimaJsonCasFormatProperties aProps) + { + properties = aProps; + } + @Override public String getId() { @@ -57,6 +65,7 @@ public AnalysisEngineDescription getWriterDescription(Project aProject, TypeSystemDescription aTSD, CAS aCAS) throws ResourceInitializationException { - return createEngineDescription(JsonWriter.class, aTSD); + return createEngineDescription(JsonWriter.class, aTSD, // + JsonWriter.PARAM_OMIT_DEFAULT_VALUES, properties.isOmitDefaultValues()); } } diff --git a/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/config/LegacyUimaJsonCasFormatProperties.java b/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/config/LegacyUimaJsonCasFormatProperties.java new file mode 100644 index 00000000000..31ff9049309 --- /dev/null +++ b/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/config/LegacyUimaJsonCasFormatProperties.java @@ -0,0 +1,19 @@ +package de.tudarmstadt.ukp.inception.io.jsoncas.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("format.json-cas-legacy") +public class LegacyUimaJsonCasFormatProperties +{ + private boolean omitDefaultValues = false; + + public void setOmitDefaultValues(boolean aOmitDefaultValues) + { + omitDefaultValues = aOmitDefaultValues; + } + + public boolean isOmitDefaultValues() + { + return omitDefaultValues; + } +} diff --git a/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/config/UimaJsonCasSupportAutoConfiguration.java b/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/config/UimaJsonCasSupportAutoConfiguration.java index a4c53297865..c4b3256f651 100644 --- a/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/config/UimaJsonCasSupportAutoConfiguration.java +++ b/inception/inception-io-json/src/main/java/de/tudarmstadt/ukp/inception/io/jsoncas/config/UimaJsonCasSupportAutoConfiguration.java @@ -18,6 +18,7 @@ package de.tudarmstadt.ukp.inception.io.jsoncas.config; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -26,14 +27,16 @@ import de.tudarmstadt.ukp.inception.io.jsoncas.UimaJsonCasFormatSupport; @Configuration +@EnableConfigurationProperties(LegacyUimaJsonCasFormatProperties.class) public class UimaJsonCasSupportAutoConfiguration { @ConditionalOnProperty(prefix = "format.json-cas-legacy", name = "enabled", // havingValue = "true", matchIfMissing = false) @Bean - public LegacyUimaJsonFormatSupport legacyUimaJsonFormatSupport() + public LegacyUimaJsonFormatSupport legacyUimaJsonFormatSupport( + LegacyUimaJsonCasFormatProperties aProps) { - return new LegacyUimaJsonFormatSupport(); + return new LegacyUimaJsonFormatSupport(aProps); } @ConditionalOnProperty(prefix = "format.json-cas", name = "enabled", // diff --git a/inception/inception-io-json/src/main/resources/META-INF/asciidoc/user-guide/formats-uimajson-legacy.adoc b/inception/inception-io-json/src/main/resources/META-INF/asciidoc/user-guide/formats-uimajson-legacy.adoc index f3f1467bd84..263356b2a72 100644 --- a/inception/inception-io-json/src/main/resources/META-INF/asciidoc/user-guide/formats-uimajson-legacy.adoc +++ b/inception/inception-io-json/src/main/resources/META-INF/asciidoc/user-guide/formats-uimajson-legacy.adoc @@ -23,7 +23,6 @@ CAUTION: Legacy feature. To use this functionality, you need to enable it first Support for this feature will be removed in a future version. The replacement is <>. ==== - This is an old and deprecated UIMA CAS JSON format which can be exported but not imported. It should no longer be used. Instead, one should turn to <>. @@ -31,6 +30,10 @@ The format does support custom layers. For more details on this format, please refer to the link:https://uima.apache.org/d/uimaj-current/references.html#ugr.ref.json[UIMA Reference Guide]. +By default, the format writes all values to the JSON output, even if the values are the default values +in JSON (e.g. `0` for numbers or `false` for booleans). You can configure this behavior by setting +`format.json-cas-legacy.omit-default-values` to `true` or `false` (default) respectively. + [cols="2,1,1,1,3"] |==== | Format | Read | Write | Custom Layers | Description @@ -41,4 +44,3 @@ For more details on this format, please refer to the link:https://uima.apache.or | yes | UIMA CAS JSON (legacy) |==== -