Class SerializationContext<T>

java.lang.Object
cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext<T>
Type Parameters:
T - Type of the value
All Implemented Interfaces:
JsonLdContext

public class SerializationContext<T> extends Object implements JsonLdContext
Represents the current serialization context.

This means the value being serialized, and optionally the target JSON-LD term identifier and field.

Note that term and field may not always be available, e.g., when a collection element is being serialized, neither is set.

This class also provides access to the JSON-LD context (if it is used). However, note that for selected serialization methods the context may be just a stub with no bearing on the serialization output.

  • Constructor Details

    • SerializationContext

      public SerializationContext(String term, T value, JsonLdContext jsonLdContext)
    • SerializationContext

      public SerializationContext(Field field, T value, JsonLdContext jsonLdContext)
    • SerializationContext

      public SerializationContext(T value, JsonLdContext jsonLdContext)
    • SerializationContext

      public SerializationContext(String term, Field field, T value, JsonLdContext jsonLdContext)
  • Method Details

    • getTerm

      public String getTerm()
    • getField

      public Field getField()
    • getFieldName

      public String getFieldName()
    • getValue

      public T getValue()
    • getJsonLdContext

      public JsonLdContext getJsonLdContext()
    • setJsonLdContext

      public void setJsonLdContext(JsonLdContext jsonLdContext)
    • registerTermMapping

      public void registerTermMapping(String term, String iri)
      Description copied from interface: JsonLdContext
      Registers the specified term mapping in this context.

      Typically, the term would be Java attribute (field) name and iri would be the IRI to which this field is mapped.

      Specified by:
      registerTermMapping in interface JsonLdContext
      Parameters:
      term - Mapped term
      iri - IRI to which the term is mapped
    • registerTermMapping

      public void registerTermMapping(String term, ObjectNode mappedNode)
      Description copied from interface: JsonLdContext
      Registers the specified term mapping in this context.

      Compared to JsonLdContext.registerTermMapping(String, String), this method allows registering more complex mapping like language containers or typed literals.

      Specified by:
      registerTermMapping in interface JsonLdContext
      Parameters:
      term - Mapped term
      mappedNode - Node to which the term is mapped
    • getTermMapping

      public Optional<JsonNode> getTermMapping(String term)
      Description copied from interface: JsonLdContext
      Gets the mapping for the specified term (if it exists).
      Specified by:
      getTermMapping in interface JsonLdContext
      Parameters:
      term - Term to get mapping for
      Returns:
      Optional mapping node
    • hasTermMapping

      public boolean hasTermMapping(String term)
      Description copied from interface: JsonLdContext
      Checks whether this JSON-LD context contains mapping for the specified term.
      Specified by:
      hasTermMapping in interface JsonLdContext
      Parameters:
      term - Term to search mapping for
      Returns:
      true if a mapping is already defined for the term, false otherwise
    • getMappedTerm

      public Optional<String> getMappedTerm(String iri)
      Description copied from interface: JsonLdContext
      Gets the term mapped to the specified identifier (if it exists).

      This method checks term mapping in this context and finds a term that is mapped to the specified identifier.

      Specified by:
      getMappedTerm in interface JsonLdContext
      Parameters:
      iri - Identifier the term is mapped to
      Returns:
      Optional mapped term, empty optional if there is no such term mapping
    • isCurrentEmpty

      public boolean isCurrentEmpty()
      Description copied from interface: JsonLdContext
      Checks whether this particular JSON-LD context is empty.

      Term mapping inherited from any parent contexts is not considered.

      Specified by:
      isCurrentEmpty in interface JsonLdContext
      Returns:
      true if this context is empty, false otherwise
    • getContextNode

      public ObjectNode getContextNode()
      Description copied from interface: JsonLdContext
      Returns an ObjectNode representing this context.

      The result can thus be added to serialization output.

      Specified by:
      getContextNode in interface JsonLdContext
      Returns:
      JsonNode with registered mappings
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object