diff --git a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/InstanceType.java b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/InstanceType.java index 8d72ec7a..fdb84a6c 100644 --- a/api/src/main/java/io/github/sebastiantoepfer/jsonschema/InstanceType.java +++ b/api/src/main/java/io/github/sebastiantoepfer/jsonschema/InstanceType.java @@ -24,6 +24,7 @@ package io.github.sebastiantoepfer.jsonschema; import jakarta.json.JsonNumber; +import jakarta.json.JsonString; import jakarta.json.JsonValue; import java.math.BigDecimal; import java.util.Arrays; @@ -33,7 +34,7 @@ /** * see: http://json-schema.org/draft/2020-12/json-schema-core.html#name-instance-data-model */ -public enum InstanceType { +public enum InstanceType implements JsonString { NULL(JsonValue.ValueType.NULL), BOOLEAN(JsonValue.ValueType.TRUE, JsonValue.ValueType.FALSE), OBJECT(JsonValue.ValueType.OBJECT), @@ -74,6 +75,21 @@ public boolean isInstance(final JsonValue value) { @Override public String toString() { + return getString(); + } + + @Override + public CharSequence getChars() { + return getString(); + } + + @Override + public String getString() { return name().toLowerCase(Locale.US); } + + @Override + public ValueType getValueType() { + return JsonValue.ValueType.STRING; + } } diff --git a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/InstanceTypeTest.java b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/InstanceTypeTest.java index 8fb737e6..1acff83b 100644 --- a/api/src/test/java/io/github/sebastiantoepfer/jsonschema/InstanceTypeTest.java +++ b/api/src/test/java/io/github/sebastiantoepfer/jsonschema/InstanceTypeTest.java @@ -24,6 +24,7 @@ package io.github.sebastiantoepfer.jsonschema; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -94,6 +95,16 @@ static Stream provideWithName() { ); } + @Test + void should_be_from_json_type_string() { + assertThat(InstanceType.INTEGER.getValueType(), is(JsonValue.ValueType.STRING)); + } + + @Test + void should_retrun_his_value_as_charsquence() { + assertThat(InstanceType.INTEGER.getChars(), hasToString("integer")); + } + @Test void should_be_createable_from_lowercase_value() { assertThat(InstanceType.fromString("object"), is(InstanceType.OBJECT));