Skip to content

Commit

Permalink
Fixes a problem where PrimitiveFormControlData would not be deseriali…
Browse files Browse the repository at this point in the history
…zed correctly if the data is a literal

This partly addresses who-icatx/icatx-project#64
  • Loading branch information
matthewhorridge committed Jul 1, 2024
1 parent c9f32ee commit 6cfadbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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.*;

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
}

0 comments on commit 6cfadbc

Please sign in to comment.