Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public HalFormsBody<?> deserialize(
jsonParser, HalFormsBody.class, "Expected object node, got " + treeNode);
}

Object representation =
deserializationContext.readValue(
createJsonParser(deserializationContext, objectNode), representationType);

JsonNode links = objectNode.get("_links");
JsonNode links = objectNode.remove("_links");
Map<String, Link> linkByName;
if (links == null) {
linkByName = Map.of();
Expand All @@ -67,7 +63,7 @@ public HalFormsBody<?> deserialize(
createJsonParser(deserializationContext, links), mapType);
}

JsonNode templates = objectNode.get("_templates");
JsonNode templates = objectNode.remove("_templates");
Map<String, Template> templateByKey;
if (templates == null) {
templateByKey = Map.of();
Expand All @@ -81,6 +77,10 @@ public HalFormsBody<?> deserialize(
createJsonParser(deserializationContext, templates), mapType);
}

Object representation =
deserializationContext.readValue(
createJsonParser(deserializationContext, objectNode), representationType);

return new HalFormsBody<>(representation, linkByName, templateByKey);
}

Expand Down
32 changes: 32 additions & 0 deletions src/test/java/com/cosium/hal_model2/HalFormsBodyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -108,6 +109,37 @@ void test2() {
assertThat(property.type()).isEqualTo("text");
}

@Test
@DisplayName("The body's representation excludes HAL metadata")
void test3() {
String json =
JSON.std
.composeString()
.startObject()
.startObjectProperty("_links")
.startObjectProperty("self")
.put("href", "http://localhost/form-test:put")
.end()
.end()
.startObjectProperty("_templates")
.startObjectProperty("default")
.put("method", "PUT")
.startArrayProperty("properties")
.startObject()
.put("name", "foo")
.end()
.end()
.end()
.end()
.end()
.finish();

HalFormsBody<Map<String, Object>> halFormsBody =
TestJsonMapper.INSTANCE.readValue(json, new TypeReference<>() {});

assertThat(halFormsBody.representation()).isEmpty();
}

private record User(@JsonProperty("username") String username) {}

private record ContentList<T>(@JsonProperty("content") @Nullable List<T> content) {}
Expand Down
Loading