Siren4J

This is a java library to help with the creation and use of Hypermedia entities as specified by the Siren hypermedia specification. See https://github.com/kevinswiber/siren for more detail on the specification.

License

License

Categories

Categories

Siren4J Data Data Formats Hypermedia Types
GroupId

GroupId

com.googlecode.siren4j
ArtifactId

ArtifactId

siren4j
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Siren4J
This is a java library to help with the creation and use of Hypermedia entities as specified by the Siren hypermedia specification. See https://github.com/kevinswiber/siren for more detail on the specification.
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

https://github.com/eserating/siren4j.git

Download siren4j

How to add to project

<!-- https://jarcasting.com/artifacts/com.googlecode.siren4j/siren4j/ -->
<dependency>
    <groupId>com.googlecode.siren4j</groupId>
    <artifactId>siren4j</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.googlecode.siren4j/siren4j/
implementation 'com.googlecode.siren4j:siren4j:2.1.0'
// https://jarcasting.com/artifacts/com.googlecode.siren4j/siren4j/
implementation ("com.googlecode.siren4j:siren4j:2.1.0")
'com.googlecode.siren4j:siren4j:jar:2.1.0'
<dependency org="com.googlecode.siren4j" name="siren4j" rev="2.1.0">
  <artifact name="siren4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.googlecode.siren4j', module='siren4j', version='2.1.0')
)
libraryDependencies += "com.googlecode.siren4j" % "siren4j" % "2.1.0"
[com.googlecode.siren4j/siren4j "2.1.0"]

Dependencies

compile (6)

Group / Artifact Type Version
com.fasterxml.jackson.jaxrs : jackson-jaxrs-json-provider jar 2.7.0
org.apache.commons : commons-lang3 jar 3.5
commons-collections : commons-collections jar 3.2.2
com.google.guava : guava jar 21.0
org.reflections : reflections jar 0.9.9-RC1
org.slf4j : slf4j-log4j12 jar 1.7.5

provided (2)

Group / Artifact Type Version
javax.ws.rs : javax.ws.rs-api jar 2.0.1
org.slf4j : slf4j-api jar 1.7.5

runtime (1)

Group / Artifact Type Version
log4j : log4j jar 1.2.17

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
com.jayway.jsonpath : json-path-assert jar 2.2.0
uk.co.datumedge : hamcrest-json jar 0.2

Project Modules

There are no modules declared in this project.

This is a java library to help with the creation and use of
Hypermedia entities as specified by the Siren hypermedia specification. See https://github.com/kevinswiber/siren for more detail on the specification.

It contains classes to that represent the Siren components (Entity, Link, Action, Field). See: https://github.com/eserating/siren4j/wiki/Siren4J-Components

These can be easily built with a fluent builder API.

EXAMPLE BUILDER:
   
    // Create a new self Link
    Link selfLink = LinkBuilder.newInstance()
       .setRelationship(Link.RELATIONSHIP_SELF)
       .setHref("/self/link")
       .build();

    // Create a new Entity
    Entity result = EntityBuilder.newInstance()
       .setEntityClass("test")
       .addProperty("foo", "hello")
       .addProperty("number", 1)
       .addLink(selfLink)
       .build();

See: https://github.com/eserating/siren4j/wiki/Fluent-Builder-API

There is also a resource API that simplifies entity creation and management using reflection and annotations.

EXAMPLE RESOURCE:

@Siren4JEntity(name = "video", uri = "/videos/{id}")
public class Video extends BaseResource {
    
    private String id;    
    private String name;
    private String description;
    private String genre;
    private Rating rating;
    @Siren4JSubEntity(uri = "/video/{parent.id}/reviews", embeddedLink = true)
    private CollectionResource<Review> reviews;
            
    public String getId() {return id;}
    public void setId(String id) {this.id = id;}
    public String getName() {return name;}
    public void setName(String name) {this.name = name;}
    public String getDescription() {return description;}
    public void setDescription(String description) {this.description = description;}
    public String getGenre() {return genre;}
    public void setGenre(String genre) {this.genre = genre;}
    public Rating getRating() {return rating;}
    public void setRating(Rating rating) {this.rating = rating;}
    public CollectionResource<Review> getReviews() {return reviews;}
    public void setReviews(CollectionResource<Review> reviews) {this.reviews = reviews;}


    public enum Rating {G, PG, PG13, R, NR, X}

}

AN INSTANCE OF A RESOURCE CLASS CAN BE CONVERTED LIKE THIS:

    ResourceConverter converter = ReflectingConverter.newInstance();
    Entity videoEntity = converter.toEntity(videoResource);

AND WILL RESULT IN SIREN JSON THAT LOOKS LIKE THIS:

{
  "class":[
    "video"
  ],
  "properties":{
    "name":"Star Wars",
    "id":"z1977",
    "description":"An epic science fiction space opera",
    "genre":"scifi",
    "rating":"PG"
  },
  "entities":[
    {
      "class":[
        "siren4J.collectionResource",
        "collection"
      ],
      "rel":[
        "reviews"
      ],
      "href":"/video/z1977/reviews"
    }
  ],
  "links":[
    {
      "rel":[
        "self"
      ],
      "href":"/videos/z1977"
    }
  ]
}

See: https://github.com/eserating/siren4j/wiki/Siren4J-Resource-API

[http://wiki.siren4j.googlecode.com/hg/javadoc/index.html JavaDoc]

Note: This projects documentation is a work in progress.

Versions

Version
2.1.0
2.0.0
1.3.0
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.14
1.0.11
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0