Skip to content

Commit

Permalink
change datetime from long to string
Browse files Browse the repository at this point in the history
  • Loading branch information
DC2-DanielKrueger committed Dec 11, 2024
1 parent 5e6ae88 commit 6a87cb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public BuiltinJsonSchema() {
classToJsonSchema.put(BuiltinDataType.Boolean,
createJsonSchemaForBuiltinType("Boolean JsonSchema", BuiltinDataType.Boolean));

classToJsonSchema.put(BuiltinDataType.SByte, createJsonSchemaForBuiltinType(" SByte JsonSchema", BuiltinDataType.SByte));
classToJsonSchema.put(BuiltinDataType.Byte, createJsonSchemaForBuiltinType(" Byte JsonSchema", BuiltinDataType.Byte));
classToJsonSchema.put(BuiltinDataType.SByte,
createJsonSchemaForBuiltinType(" SByte JsonSchema", BuiltinDataType.SByte));
classToJsonSchema.put(BuiltinDataType.Byte,
createJsonSchemaForBuiltinType(" Byte JsonSchema", BuiltinDataType.Byte));

classToJsonSchema.put(BuiltinDataType.UInt64,
createJsonSchemaForBuiltinType("UInt64 JsonSchema", BuiltinDataType.UInt64));
Expand Down Expand Up @@ -110,8 +112,7 @@ public BuiltinJsonSchema() {
}

private @NotNull JsonNode createJsonSchemaForBuiltinType(
final @NotNull String title,
final @NotNull BuiltinDataType builtinDataType) {
final @NotNull String title, final @NotNull BuiltinDataType builtinDataType) {
final ObjectNode rootNode = OBJECT_MAPPER.createObjectNode();
final ObjectNode propertiesNode = OBJECT_MAPPER.createObjectNode();
final ObjectNode valueNode = OBJECT_MAPPER.createObjectNode();
Expand Down Expand Up @@ -156,6 +157,10 @@ public static void populatePropertiesForBuiltinType(
case LocalizedText:
nestedPropertiesNode.set("type", new TextNode("string"));
return;
case DateTime:
nestedPropertiesNode.set("type", new TextNode("string"));
nestedPropertiesNode.set("format", new TextNode("date-time"));
return;
case Int16:
nestedPropertiesNode.set("type", new TextNode(INTEGER_DATA_TYPE));
nestedPropertiesNode.set(MINIMUM_KEY_WORD, new ShortNode(Short.MIN_VALUE));
Expand All @@ -177,7 +182,6 @@ public static void populatePropertiesForBuiltinType(
nestedPropertiesNode.set(MINIMUM_KEY_WORD, new LongNode(UInteger.MIN_VALUE));
nestedPropertiesNode.set(MAXIMUM_KEY_WORD, new LongNode(UInteger.MAX_VALUE));
return;
case DateTime:
case Int64:
nestedPropertiesNode.set("type", new TextNode(INTEGER_DATA_TYPE));
nestedPropertiesNode.set(MINIMUM_KEY_WORD, new LongNode(Long.MIN_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.time.Instant;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -359,8 +361,8 @@ private static UUID extractGuid(final JsonNode jsonNode) {
}

private static DateTime extractDateTime(final JsonNode jsonNode) {
if (jsonNode.isLong()) {
return new DateTime(jsonNode.asLong());
if (jsonNode.isTextual()) {
return new DateTime(Date.from(Instant.parse(jsonNode.asText())));
}
throw createException(jsonNode, BuiltinDataType.DateTime.name());
}
Expand All @@ -372,6 +374,7 @@ private static DateTime extractDateTime(final JsonNode jsonNode) {
throw createException(jsonNode, BuiltinDataType.String.name());
}


static double extractDouble(final JsonNode jsonNode) {
if (jsonNode.isDouble()) {
return jsonNode.asDouble();
Expand Down

0 comments on commit 6a87cb5

Please sign in to comment.