SURF Reference Implementation
Source Code

Maven Dependency


SURF Parser

Parse File

import*;SurfParser parser = new SurfParser();
Optional<Object> surf;
Path = Paths.get("");
try (final InputStream inputStream = newInputStream(path)) {
  surf = parser.parse(inputStream);

Parsing Results

The returned SURF data will be one of the following, based upon the root resource in the file:

  • Optional.empty() if the file was empty.
  • A value object (e.g. java.lang.Integer) if the root resource was a SURF literal.
  • A implementation of a collection type (e.g. java.util.Set<>) if it was a SURF collection.
  • An instance of SurfObject if it was a SURF object.

Access SURF Data

SurfObject user = (SurfObject)surf
    .orElseThrow(() -> new IOException("User file empty."));
URI userTag = user.getTag()
    .orElseThrow(() -> new IOException("Missing user IRI."));
String userName = (String)user.getPropertyValue("name")
    .orElseThrow(() -> new IOException("Missing user name."));
Optional<Object> userJoined = user.getPropertyValue("joined");
userJoined.ifPresent(joined -> {
  System.out.println(String.format("User joined %d days ago.",

SURF Serializer

Create SurfObject



userTag = URI.fromString("urn:uuid:bb8e7dbe-f0b4-4d94"
SurfObject user = new SurfObject(userTag, "example-User");
user.setPropertyValue("name", "Jane Doe");
LocalDate joined = LocalDate.of(2016, Month.JANUARY, 23);
user.setPropertyValue("joined", joined);

Serialize File

SurfSerializer serializer = new SurfSerializer();

Path = Paths.get("");
try (final OutputStream outputStream = newOutputStream(path)) {
  serializer.serialize(outputStream, user);