Skip to content

Latest commit

 

History

History
84 lines (66 loc) · 1.72 KB

README.md

File metadata and controls

84 lines (66 loc) · 1.72 KB

siren-util

Java Badge Kotlin Badge Build Status

Build and parse Siren hypermedia compliant JSON representations of entities.

Example

val properties = mapOf(
  "orderNumber" to 42,
  "itemCount" to 3,
  "status" to "pending"
)

// Building.
val siren = Root
  .newBuilder()
  .clazz("order")
  .properties(properties)
  .links(
    Link.newBuilder("self", URI.create("https://example.com/orders/42")).build()
  )
  .build()

val json = siren.toJson()

// Parsing.
val parsed = Root.fromJson(json)
if (parsed.getProperties() != null) {
  parsed.getProperties().get("status")
}

Result:

{
  "class": [
    "order"
  ],
  "properties": {
    "orderNumber": 42,
    "itemCount": 3,
    "status": "pending"
  },
  "links": [
    {
      "rel": [
        "self"
      ],
      "href": "https://example.com/orders/42"
    }
  ]
}

See tests for more examples.

Contributing

Snapshot tests

Files in src/test/resources that ends with .snapshot are generated by the tests and updated automatically by setting REGENERATE_SNAPSHOTS=true system property.

Example:

mvn test -DREGENERATE_SNAPSHOTS=true

When a snapshot fails the easiest way to compare the changes are by regenering snapshots and using Git diff.

Linting

This project uses ktlint to enforce code style. Use mvn ktlint:format to sort most formatting issues if the build fails.