Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eserating-chwy/siren4j
Java library for the Siren Hypermedia Type Specification
https://github.com/eserating-chwy/siren4j
Last synced: about 2 months ago
JSON representation
Java library for the Siren Hypermedia Type Specification
- Host: GitHub
- URL: https://github.com/eserating-chwy/siren4j
- Owner: eserating-chwy
- License: mit
- Created: 2015-07-22T00:24:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-05-03T14:17:27.000Z (8 months ago)
- Last Synced: 2024-08-01T18:25:03.306Z (5 months ago)
- Language: Java
- Homepage:
- Size: 366 KB
- Stars: 25
- Watchers: 6
- Forks: 15
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: License
Awesome Lists containing this project
- awesome-java - Siren4J - Library for the Siren specification. (Projects / Hypermedia Types)
README
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-ComponentsThese can be easily built with a fluent builder API.
```java
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:
```java
@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 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 getReviews() {return reviews;}
public void setReviews(CollectionResource reviews) {this.reviews = reviews;}public enum Rating {G, PG, PG13, R, NR, X}
}
```
AN INSTANCE OF A RESOURCE CLASS CAN BE CONVERTED LIKE THIS:
```java
ResourceConverter converter = ReflectingConverter.newInstance();
Entity videoEntity = converter.toEntity(videoResource);
```AND WILL RESULT IN SIREN JSON THAT LOOKS LIKE THIS:
```xml
{
"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.