DZone
Integration Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > Introducing Siren 4 Java EE 1.0

Introducing Siren 4 Java EE 1.0

When implementing a Hypermedia-driven REST API you may need to choose a content type upfront. Check out how to use the Siren content type together with Java EE.

Sebastian Daschner user avatar by
Sebastian Daschner
·
Jun. 06, 16 · Integration Zone · News
Like (2)
Save
Tweet
3.04K Views

Join the DZone community and get the full member experience.

Join For Free

When implementing a Hypermedia-driven REST API you may need to choose a content type upfront. If you use the Siren content type together with Java EE there are several approaches to create Siren entity responses.

As your links and actions in your responses may dynamically change depending on your business logic (e.g. some links or actions are only valid in certain situations), it makes sense to use a programmatic rather than declarative approach. Siren4J offers a simple way to both programmatically and declaratively create Siren responses. However this library contains a few third-party dependencies, for instance Jackson.

If you want a leaner approach using plain Java EE 7 you can either use JSON output created by JSONP or a lean library called Siren 4 Java EE. The idea of the latter is to only depend on the Java EE 7 API and therefore use JSONP internally.

Siren 4 Java EE is used as follows:

<dependency>
 <groupId>com.sebastian-daschner</groupId>
 <artifactId>siren4javaee</artifactId>
 <version>1.0</version>
</dependency>
JsonObject bookEntity = Siren.createEntityBuilder()
 .addClass("book")
 .addProperty("isbn", book.getIsbn())
 .addProperty("name", book.getName())
 .addProperty("author", book.getAuthor())
 .addProperty("availability", book.getAvailability().toString())
 .addProperty("price", book.getPrice())
 .addLink(bookUri, "self")
 .addAction(Siren.createActionBuilder()
 .setName("add-to-cart")
 .setTitle("Add book to cart")
 .setMethod(HttpMethod.POST)
 .setHref(shoppingCartUri)
 .setType(MediaType.APPLICATION_JSON)
 .addField("isbn", FieldType.TEXT)
 .addField("quantity", FieldType.NUMBER)).build();

For a more comprehensive example see the siren4javaee approach in Hypermedia with JAX-RS.

Java EE Java (programming language)

Published at DZone with permission of Sebastian Daschner. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Toying With Kotlin’s Context Receivers
  • What Is Cloud-Native Architecture?
  • Image Classification Using SingleStore DB, Keras, and Tensorflow
  • How to Use Geofences for Precise Audience Messaging

Comments

Integration Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo