From 6cfadbc0cfb0f1835d7211e870a74bbe36dc3de3 Mon Sep 17 00:00:00 2001 From: Matthew Horridge Date: Mon, 1 Jul 2024 13:19:09 -0700 Subject: [PATCH] Fixes a problem where PrimitiveFormControlData would not be deserialized correctly if the data is a literal This partly addresses https://github.com/who-icatx/icatx-project/issues/64 --- .../data/PrimitiveFormControlDataProxy.java | 6 ++---- .../forms/data/PrimitiveFormControlDataTest.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataProxy.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataProxy.java index 0961aa8..e12d425 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataProxy.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataProxy.java @@ -1,8 +1,6 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import org.semanticweb.owlapi.model.*; import uk.ac.manchester.cs.owl.owlapi.*; @@ -16,7 +14,7 @@ public record PrimitiveFormControlDataProxy(@JsonInclude(JsonInclude.Include.NON_EMPTY) @Nullable String iri, @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("@type") @Nullable String type, @JsonInclude(JsonInclude.Include.NON_EMPTY) @Nullable String value, - @JsonInclude(JsonInclude.Include.NON_EMPTY) @Nullable String datatype, + @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("type") @Nullable String datatype, @JsonInclude(JsonInclude.Include.NON_EMPTY) @Nullable String lang) { public PrimitiveFormControlData toPrimitiveFormControlData() { diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataTest.java index 80bc850..2b34581 100644 --- a/src/test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataTest.java @@ -6,7 +6,7 @@ import org.springframework.boot.test.autoconfigure.json.*; import org.springframework.boot.test.json.JacksonTester; -import java.io.IOException; +import java.io.*; import static org.assertj.core.api.Assertions.assertThat; @@ -26,7 +26,19 @@ void setUp() { void shouldSerializeBooleanLiteral() throws IOException { var data = PrimitiveFormControlData.get(true); var written = tester.write(data); - assertThat(written).hasJsonPathStringValue("value", "true"); System.out.println(written.getJson()); + assertThat(written).hasJsonPathStringValue("value", "true"); + assertThat(written).hasJsonPathValue("type"); + } + + @Test + void shouldDeserializeBooleanLiteral() throws IOException { + var json = """ + {"value":"true","type":"http://www.w3.org/2001/XMLSchema#boolean"} + """; + var read =tester.read(new StringReader(json)); + assertThat(read.getObject().asLiteral()).isPresent(); + assertThat(read.getObject().asLiteral().get().getLiteral()).isEqualTo("true"); + assertThat(read.getObject().asLiteral().get().isBoolean()).isTrue(); } } \ No newline at end of file