cls) {
* @return New collection instance
*/
public static Collection> createCollection(CollectionType type) {
- switch (type) {
- case LIST:
- return new ArrayList<>();
- case SET:
- return new HashSet<>();
- default:
- throw new IllegalArgumentException("Unsupported collection type " + type);
- }
+ return switch (type) {
+ case LIST -> new ArrayList<>();
+ case SET -> new HashSet<>();
+ };
}
/**
@@ -249,8 +249,9 @@ public static void verifyPropertiesFieldType(Field field) {
/**
* Checks whether the specified class represents an individual reference and not a complex object.
- *
+ *
* Individual references are identifiers or enum constants mapped to individuals.
+ *
* @param cls Class to check
* @return {@code true} when the type represents an individual, {@code false} otherwise
* @see #isIdentifierType(Class)
diff --git a/src/main/java/cz/cvut/kbss/jsonld/deserialization/util/ClasspathScanner.java b/src/main/java/cz/cvut/kbss/jsonld/deserialization/util/ClasspathScanner.java
index c716d34..1e172a5 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/deserialization/util/ClasspathScanner.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/deserialization/util/ClasspathScanner.java
@@ -133,7 +133,7 @@ protected void processJarFile(URL jarResource, String packageName) {
}
}
} catch (IOException e) {
- LOG.error("Unable to scan classes in JAR file " + jarPath, e);
+ LOG.error("Unable to scan classes in JAR file {}", jarPath, e);
}
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/CompactedJsonLdSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/CompactedJsonLdSerializer.java
index 82018a3..9ecbf44 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/CompactedJsonLdSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/CompactedJsonLdSerializer.java
@@ -24,14 +24,21 @@
import cz.cvut.kbss.jsonld.serialization.serializer.LiteralValueSerializers;
import cz.cvut.kbss.jsonld.serialization.serializer.ObjectGraphValueSerializers;
import cz.cvut.kbss.jsonld.serialization.serializer.ValueSerializers;
-import cz.cvut.kbss.jsonld.serialization.serializer.compact.*;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.DefaultValueSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.IdentifierSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.IndividualSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.MultilingualStringSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.NumberSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.ObjectPropertyValueSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.TypesSerializer;
import cz.cvut.kbss.jsonld.serialization.serializer.compact.datetime.TemporalAmountSerializer;
import cz.cvut.kbss.jsonld.serialization.serializer.compact.datetime.TemporalSerializer;
import cz.cvut.kbss.jsonld.serialization.serializer.datetime.DateSerializer;
import cz.cvut.kbss.jsonld.serialization.traversal.ObjectGraphTraverser;
import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContextFactory;
-import java.time.*;
+import java.time.Duration;
+import java.time.Period;
import java.util.Date;
/**
@@ -57,19 +64,14 @@ protected ValueSerializers initSerializers() {
valueSerializers.registerTypesSerializer(new TypesSerializer());
valueSerializers.registerIndividualSerializer(new IndividualSerializer());
final TemporalSerializer ts = new TemporalSerializer();
- valueSerializers.registerSerializer(LocalDate.class, ts);
// Register the same temporal serializer for each of the types it supports (needed for key-based map access)
- valueSerializers.registerSerializer(LocalDate.class, ts);
- valueSerializers.registerSerializer(LocalTime.class, ts);
- valueSerializers.registerSerializer(OffsetTime.class, ts);
- valueSerializers.registerSerializer(LocalDateTime.class, ts);
- valueSerializers.registerSerializer(OffsetDateTime.class, ts);
- valueSerializers.registerSerializer(ZonedDateTime.class, ts);
- valueSerializers.registerSerializer(Instant.class, ts);
+ TemporalSerializer.getSupportedTypes().forEach(cls -> valueSerializers.registerSerializer(cls, ts));
valueSerializers.registerSerializer(Date.class, new DateSerializer(ts));
final TemporalAmountSerializer tas = new TemporalAmountSerializer();
valueSerializers.registerSerializer(Duration.class, tas);
valueSerializers.registerSerializer(Period.class, tas);
+ final NumberSerializer numberSerializer = new NumberSerializer();
+ NumberSerializer.getSupportedTypes().forEach(cls -> valueSerializers.registerSerializer(cls, numberSerializer));
return valueSerializers;
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/ContextBuildingJsonLdSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/ContextBuildingJsonLdSerializer.java
index 2042c30..0cbed63 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/ContextBuildingJsonLdSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/ContextBuildingJsonLdSerializer.java
@@ -33,14 +33,22 @@
import cz.cvut.kbss.jsonld.serialization.serializer.ObjectGraphValueSerializers;
import cz.cvut.kbss.jsonld.serialization.serializer.ValueSerializer;
import cz.cvut.kbss.jsonld.serialization.serializer.ValueSerializers;
-import cz.cvut.kbss.jsonld.serialization.serializer.context.*;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingDefaultValueSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingIdentifierSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingIndividualSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingMultilingualStringSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingNumberSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingObjectPropertyValueSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingPluralMultilingualStringSerializer;
+import cz.cvut.kbss.jsonld.serialization.serializer.context.ContextBuildingTypesSerializer;
import cz.cvut.kbss.jsonld.serialization.serializer.context.datetime.ContextBuildingTemporalAmountSerializer;
import cz.cvut.kbss.jsonld.serialization.serializer.context.datetime.ContextBuildingTemporalSerializer;
import cz.cvut.kbss.jsonld.serialization.serializer.datetime.DateSerializer;
import cz.cvut.kbss.jsonld.serialization.traversal.ObjectGraphTraverser;
import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContextFactory;
-import java.time.*;
+import java.time.Duration;
+import java.time.Period;
import java.util.Collection;
import java.util.Date;
import java.util.Optional;
@@ -69,19 +77,16 @@ protected ValueSerializers initSerializers() {
valueSerializers.registerTypesSerializer(new ContextBuildingTypesSerializer());
valueSerializers.registerIndividualSerializer(new ContextBuildingIndividualSerializer());
final ContextBuildingTemporalSerializer ts = new ContextBuildingTemporalSerializer();
- valueSerializers.registerSerializer(LocalDate.class, ts);
// Register the same temporal serializer for each of the types it supports (needed for key-based map access)
- valueSerializers.registerSerializer(LocalDate.class, ts);
- valueSerializers.registerSerializer(LocalTime.class, ts);
- valueSerializers.registerSerializer(OffsetTime.class, ts);
- valueSerializers.registerSerializer(LocalDateTime.class, ts);
- valueSerializers.registerSerializer(OffsetDateTime.class, ts);
- valueSerializers.registerSerializer(ZonedDateTime.class, ts);
- valueSerializers.registerSerializer(Instant.class, ts);
+ ContextBuildingTemporalSerializer.getSupportedTypes()
+ .forEach(cls -> valueSerializers.registerSerializer(cls, ts));
valueSerializers.registerSerializer(Date.class, new DateSerializer(ts));
final ContextBuildingTemporalAmountSerializer tas = new ContextBuildingTemporalAmountSerializer();
valueSerializers.registerSerializer(Duration.class, tas);
valueSerializers.registerSerializer(Period.class, tas);
+ final ContextBuildingNumberSerializer ns = new ContextBuildingNumberSerializer();
+ ContextBuildingNumberSerializer.getSupportedTypes()
+ .forEach(cls -> valueSerializers.registerSerializer(cls, ns));
return valueSerializers;
}
@@ -114,7 +119,8 @@ private void ensureContextNodeNotPresent(CompositeNode> root, JsonNode rootCtx
private JsonLdTreeBuilder initTreeBuilder(ObjectGraphTraverser traverser,
JsonLdContextFactory jsonLdContextFactory) {
- final ContextBuildingObjectPropertyValueSerializer opSerializer = new ContextBuildingObjectPropertyValueSerializer(traverser);
+ final ContextBuildingObjectPropertyValueSerializer opSerializer =
+ new ContextBuildingObjectPropertyValueSerializer(traverser);
opSerializer.configure(configuration());
return new JsonLdTreeBuilder(new ObjectGraphValueSerializers(serializers, opSerializer), jsonLdContextFactory);
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/JsonNodeFactory.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/JsonNodeFactory.java
index 7183c85..f7b4831 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/JsonNodeFactory.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/JsonNodeFactory.java
@@ -43,14 +43,11 @@ public static LiteralNode> createLiteralNode(Object value) {
public static LiteralNode> createLiteralNode(String name, Object value) {
final LiteralType type = determineLiteralType(value);
- switch (type) {
- case BOOLEAN:
- return createBooleanLiteralNode(name, (Boolean) value);
- case NUMBER:
- return createNumericLiteralNode(name, (Number) value);
- default:
- return createStringLiteralNode(name, value.toString());
- }
+ return switch (type) {
+ case BOOLEAN -> createBooleanLiteralNode(name, (Boolean) value);
+ case NUMBER -> createNumericLiteralNode(name, (Number) value);
+ default -> createStringLiteralNode(name, value.toString());
+ };
}
private static LiteralType determineLiteralType(Object value) {
@@ -84,14 +81,10 @@ public static StringLiteralNode createStringLiteralNode(String name, String valu
*/
public static CollectionNode> createCollectionNode(String name, Collection> value) {
final CollectionType type = determineCollectionType(value);
- switch (type) {
- case LIST:
- return new ListNode(name);
- case SET:
- return createSetNode(name);
- default:
- throw new IllegalArgumentException("Unsupported collection type " + type);
- }
+ return switch (type) {
+ case LIST -> new ListNode(name);
+ case SET -> createSetNode(name);
+ };
}
private static CollectionType determineCollectionType(Collection> collection) {
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/model/CollectionNode.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/model/CollectionNode.java
index 075ec66..2a97456 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/model/CollectionNode.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/model/CollectionNode.java
@@ -19,6 +19,11 @@
import java.util.Collection;
+/**
+ * JSON node representing a collection.
+ *
+ * @param Node type
+ */
public abstract class CollectionNode> extends CompositeNode {
CollectionNode() {
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/SerializerUtils.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/SerializerUtils.java
index afdbf39..dd41b2a 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/SerializerUtils.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/SerializerUtils.java
@@ -70,7 +70,7 @@ public static ObjectNode createTypedTermDefinition(String term, String id, Strin
* @param type Value type to use
* @return Resulting JSON node
*/
- public static JsonNode createdTypedValueNode(String term, String value, String type) {
+ public static JsonNode createdTypedValueNode(String term, Object value, String type) {
final ObjectNode node = JsonNodeFactory.createObjectNode(term);
node.addItem(JsonNodeFactory.createLiteralNode(JsonLd.TYPE, type));
node.addItem(JsonNodeFactory.createLiteralNode(JsonLd.VALUE, value));
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/NumberSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/NumberSerializer.java
new file mode 100644
index 0000000..a2e6c84
--- /dev/null
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/NumberSerializer.java
@@ -0,0 +1,54 @@
+package cz.cvut.kbss.jsonld.serialization.serializer.compact;
+
+import cz.cvut.kbss.jopa.vocabulary.XSD;
+import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
+import cz.cvut.kbss.jsonld.serialization.serializer.SerializerUtils;
+import cz.cvut.kbss.jsonld.serialization.serializer.ValueSerializer;
+import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Serializes numeric values.
+ */
+public class NumberSerializer implements ValueSerializer {
+
+ @Override
+ public JsonNode serialize(Number value, SerializationContext ctx) {
+ Objects.requireNonNull(value);
+ return SerializerUtils.createdTypedValueNode(ctx.getTerm(), value, getDatatype(value));
+ }
+
+ protected String getDatatype(Number value) {
+ if (value instanceof Integer) {
+ return XSD.INT;
+ } else if (value instanceof Long) {
+ return XSD.LONG;
+ } else if (value instanceof Double) {
+ return XSD.DOUBLE;
+ } else if (value instanceof Float) {
+ return XSD.FLOAT;
+ } else if (value instanceof Short) {
+ return XSD.SHORT;
+ } else if (value instanceof BigInteger) {
+ return XSD.INTEGER;
+ } else if (value instanceof BigDecimal) {
+ return XSD.DECIMAL;
+ } else {
+ throw new IllegalArgumentException("Unsupported numeric literal type " + value.getClass());
+ }
+ }
+
+ /**
+ * Gets a list of Java types supported by this serializer.
+ *
+ * @return List of Java classes
+ */
+ public static List> getSupportedTypes() {
+ return List.of(Integer.class, Long.class, Double.class, Float.class, Short.class, BigInteger.class,
+ BigDecimal.class);
+ }
+}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/datetime/TemporalSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/datetime/TemporalSerializer.java
index 46798f5..c98e127 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/datetime/TemporalSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/datetime/TemporalSerializer.java
@@ -25,8 +25,15 @@
import cz.cvut.kbss.jsonld.serialization.serializer.datetime.DateTimeSerializer;
import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext;
-import java.time.*;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.ZonedDateTime;
import java.time.temporal.TemporalAccessor;
+import java.util.List;
/**
* Serializes Java 8 date/time values represented by the {@link TemporalAccessor} interface.
@@ -41,7 +48,8 @@ public TemporalSerializer() {
this(new IsoDateTimeSerializer(), new LocalDateSerializer(), new TimeSerializer());
}
- protected TemporalSerializer(DateTimeSerializer dateTimeSerializer, LocalDateSerializer dateSerializer, TimeSerializer timeSerializer) {
+ protected TemporalSerializer(DateTimeSerializer dateTimeSerializer, LocalDateSerializer dateSerializer,
+ TimeSerializer timeSerializer) {
this.dateTimeSerializer = dateTimeSerializer;
this.dateSerializer = dateSerializer;
this.timeSerializer = timeSerializer;
@@ -64,14 +72,25 @@ public JsonNode serialize(TemporalAccessor value, SerializationContext> getSupportedTypes() {
+ return List.of(LocalDate.class, OffsetTime.class, LocalTime.class, OffsetDateTime.class, LocalDateTime.class,
+ Instant.class, ZonedDateTime.class);
+ }
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/ContextBuildingNumberSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/ContextBuildingNumberSerializer.java
new file mode 100644
index 0000000..d145774
--- /dev/null
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/ContextBuildingNumberSerializer.java
@@ -0,0 +1,26 @@
+package cz.cvut.kbss.jsonld.serialization.serializer.context;
+
+import cz.cvut.kbss.jsonld.serialization.JsonNodeFactory;
+import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
+import cz.cvut.kbss.jsonld.serialization.model.ObjectNode;
+import cz.cvut.kbss.jsonld.serialization.serializer.SerializerUtils;
+import cz.cvut.kbss.jsonld.serialization.serializer.compact.NumberSerializer;
+import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext;
+
+/**
+ * Serializes numeric values and builds a corresponding context item for them.
+ */
+public class ContextBuildingNumberSerializer extends NumberSerializer {
+
+ @Override
+ public JsonNode serialize(Number value, SerializationContext ctx) {
+ if (ctx.getTerm() != null && ctx.getFieldName() != null) {
+ final ObjectNode termDef =
+ SerializerUtils.createTypedTermDefinition(ctx.getFieldName(), ctx.getTerm(), getDatatype(value));
+ ctx.registerTermMapping(ctx.getFieldName(), termDef);
+ return JsonNodeFactory.createLiteralNode(ctx.getTerm(), value);
+ } else {
+ return super.serialize(value, ctx);
+ }
+ }
+}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingEpochBasedDateTimeSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingEpochBasedDateTimeSerializer.java
index 3b76f95..8c976b0 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingEpochBasedDateTimeSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingEpochBasedDateTimeSerializer.java
@@ -28,7 +28,7 @@ public class ContextBuildingEpochBasedDateTimeSerializer extends EpochBasedDateT
@Override
public JsonNode serialize(OffsetDateTime value, SerializationContext ctx) {
- if (ctx.getTerm() != null) {
+ if (ctx.getTerm() != null && ctx.getFieldName() != null) {
ctx.registerTermMapping(ctx.getFieldName(), ctx.getTerm());
}
return super.serialize(value, ctx);
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingIsoDateTimeSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingIsoDateTimeSerializer.java
index 4b11f3a..492abf5 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingIsoDateTimeSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingIsoDateTimeSerializer.java
@@ -32,11 +32,13 @@ public class ContextBuildingIsoDateTimeSerializer extends IsoDateTimeSerializer
@Override
public JsonNode serialize(OffsetDateTime value, SerializationContext ctx) {
- if (ctx.getTerm() != null) {
+ if (ctx.getTerm() != null && ctx.getFieldName() != null) {
final ObjectNode termDef =
SerializerUtils.createTypedTermDefinition(ctx.getFieldName(), ctx.getTerm(), XSD.DATETIME);
ctx.registerTermMapping(ctx.getFieldName(), termDef);
+ return JsonNodeFactory.createLiteralNode(ctx.getTerm(), formatter.format(value));
+ } else {
+ return super.serialize(value, ctx);
}
- return JsonNodeFactory.createLiteralNode(ctx.getTerm(), formatter.format(value));
}
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingLocalDateSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingLocalDateSerializer.java
index 5679beb..b07b976 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingLocalDateSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingLocalDateSerializer.java
@@ -32,11 +32,13 @@ public class ContextBuildingLocalDateSerializer extends LocalDateSerializer {
@Override
public JsonNode serialize(LocalDate value, SerializationContext ctx) {
- if (ctx.getTerm() != null) {
+ if (ctx.getTerm() != null && ctx.getFieldName() != null) {
final ObjectNode termDef =
SerializerUtils.createTypedTermDefinition(ctx.getFieldName(), ctx.getTerm(), XSD.DATE);
ctx.registerTermMapping(ctx.getFieldName(), termDef);
+ return JsonNodeFactory.createLiteralNode(ctx.getTerm(), FORMATTER.format(value));
+ } else {
+ return super.serialize(value, ctx);
}
- return JsonNodeFactory.createLiteralNode(ctx.getTerm(), FORMATTER.format(value));
}
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTemporalAmountSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTemporalAmountSerializer.java
index 3688a56..b0f1d90 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTemporalAmountSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTemporalAmountSerializer.java
@@ -31,11 +31,13 @@ public class ContextBuildingTemporalAmountSerializer implements ValueSerializer<
@Override
public JsonNode serialize(TemporalAmount value, SerializationContext ctx) {
- if (ctx.getTerm() != null) {
+ if (ctx.getTerm() != null && ctx.getFieldName() != null) {
final ObjectNode termDef = SerializerUtils.createTypedTermDefinition(ctx.getFieldName(), ctx.getTerm(),
XSD.DURATION);
ctx.registerTermMapping(ctx.getFieldName(), termDef);
+ return JsonNodeFactory.createLiteralNode(ctx.getTerm(), value.toString());
+ } else {
+ return SerializerUtils.createdTypedValueNode(ctx.getTerm(), value, XSD.DURATION);
}
- return JsonNodeFactory.createLiteralNode(ctx.getTerm(), value.toString());
}
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTimeSerializer.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTimeSerializer.java
index c042177..1a0f52e 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTimeSerializer.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/context/datetime/ContextBuildingTimeSerializer.java
@@ -31,11 +31,13 @@ public class ContextBuildingTimeSerializer extends cz.cvut.kbss.jsonld.serializa
@Override
public JsonNode serialize(OffsetTime value, SerializationContext ctx) {
- if (ctx.getTerm() != null) {
+ if (ctx.getTerm() != null && ctx.getFieldName() != null) {
final ObjectNode termDef =
SerializerUtils.createTypedTermDefinition(ctx.getFieldName(), ctx.getTerm(), XSD.TIME);
ctx.registerTermMapping(ctx.getFieldName(), termDef);
+ return JsonNodeFactory.createLiteralNode(ctx.getTerm(), FORMATTER.format(value));
+ } else {
+ return super.serialize(value, ctx);
}
- return JsonNodeFactory.createLiteralNode(ctx.getTerm(), FORMATTER.format(value));
}
}
diff --git a/src/main/java/cz/cvut/kbss/jsonld/serialization/traversal/PropertiesTraverser.java b/src/main/java/cz/cvut/kbss/jsonld/serialization/traversal/PropertiesTraverser.java
index 2f24d06..24ec1a8 100644
--- a/src/main/java/cz/cvut/kbss/jsonld/serialization/traversal/PropertiesTraverser.java
+++ b/src/main/java/cz/cvut/kbss/jsonld/serialization/traversal/PropertiesTraverser.java
@@ -45,8 +45,7 @@ public void traverseProperties(SerializationContext