Skip to content

Commit

Permalink
Disabling Jacksons auto-detection mode breaks rendering of HalFormsOp…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
reda-alaoui committed Dec 1, 2024
1 parent 1c3eab8 commit 2ec195c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Representation of HAL-FORMS {@code options} attribute.
*
* @author Oliver Drotbohm
* @author Réda Housni Alaoui
* @see https://rwcbook.github.io/hal-forms/#options-element
* @since 1.3
*/
Expand Down Expand Up @@ -151,6 +152,7 @@ protected AbstractHalFormsOptions(@Nullable String promptRef, @Nullable String v
*/
@Nullable
@Override
@JsonProperty
public String getPromptField() {
return promptField;
}
Expand All @@ -161,6 +163,7 @@ public String getPromptField() {
*/
@Nullable
@Override
@JsonProperty
public String getValueField() {
return valueField;
}
Expand All @@ -171,6 +174,7 @@ public String getValueField() {
*/
@Nullable
@Override
@JsonProperty
public Long getMinItems() {
return minItems;
}
Expand All @@ -181,6 +185,7 @@ public Long getMinItems() {
*/
@Nullable
@Override
@JsonProperty
public Long getMaxItems() {
return maxItems;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -83,6 +84,7 @@
/**
* @author Greg Turnquist
* @author Oliver Drotbohm
* @author Réda Housni Alaoui
*/
class Jackson2HalFormsIntegrationTest {

Expand Down Expand Up @@ -571,6 +573,44 @@ void rendersPromptedOptionsValues() throws Exception {
.isEqualTo("My Prompt");
}

@Test
// #2257
void rendersFullInlineOptions() {
Inline inline = HalFormsOptions.inline(Map.of("my-prompt-field", "foo","my-value-field", "bar")).withPromptField("my-prompt-field")
.withValueField("my-value-field")
.withMinItems(2L)
.withMaxItems(3L);

DocumentContext result = JsonPath.parse(getCuriedObjectMapper().writeObject(inline));
assertThat(result.read("$.inline[0].my-prompt-field", String.class)).isEqualTo("foo");
assertThat(result.read("$.inline[0].my-value-field", String.class)).isEqualTo("bar");
assertThat(result.read("$.promptField", String.class)).isEqualTo("my-prompt-field");
assertThat(result.read("$.valueField", String.class)).isEqualTo("my-value-field");
assertThat(result.read("$.minItems", Long.class)).isEqualTo(2L);
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
}

@Test
// #2257
void rendersFullRemoteOptions() {
Link link = Link.of("/foo{?bar}").withType(MediaType.APPLICATION_JSON_VALUE);

Remote remote = HalFormsOptions.remote(link)
.withPromptField("my-prompt-field")
.withValueField("my-value-field")
.withMinItems(2L)
.withMaxItems(3L);

DocumentContext result = JsonPath.parse(getCuriedObjectMapper().writeObject(remote));
assertThat(result.read("$.link.href", String.class)).isEqualTo("/foo{?bar}");
assertThat(result.read("$.link.type", String.class)).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
assertThat(result.read("$.link.templated", boolean.class)).isTrue();
assertThat(result.read("$.promptField", String.class)).isEqualTo("my-prompt-field");
assertThat(result.read("$.valueField", String.class)).isEqualTo("my-value-field");
assertThat(result.read("$.minItems", Long.class)).isEqualTo(2L);
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
}

@Test // #1483
void rendersRemoteOptions() {

Expand Down

0 comments on commit 2ec195c

Please sign in to comment.