jsonfeed4j

Read and write JSON Feed, as defined at https://jsonfeed.org

License

License

Categories

Categories

MOA Business Logic Libraries Machine Learning JSON Data
GroupId

GroupId

com.moandjiezana.jsonfeed
ArtifactId

ArtifactId

jsonfeed4j
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

jsonfeed4j
Read and write JSON Feed, as defined at https://jsonfeed.org
Source Code Management

Source Code Management

https://github.com/mwanji/jsonfeed4j

Download jsonfeed4j

How to add to project

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

Dependencies

provided (1)

Group / Artifact Type Version
javax.validation : validation-api jar 1.1.0.Final

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.0.0-M4

Project Modules

There are no modules declared in this project.

jsonfeed4j

jsonfeed4j is a JSON Feed reader and writer for Java 8+.

Installation

Requires Java 1.8 or above.

Add the following dependency to your POM (or equivalent for other dependency managers):

<dependency>
  <groupId>com.moandjiezana.jsonfeed</groupId>
  <artifactId>jsonfeed4j-gson</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

This binds jsonfeed4j to the Gson JSON library. If you wish to use another JSON library, you must implement your own JsonFeedReader.

Quick Start

JsonFeed jsonFeed = new GsonJsonFeedReader().read(getJsonFeedFile());
System.out.println("Author: " + jsonFeed.getAuthor().orElse(""));
jsonFeed.getItems().stream().map(Item::getUrl).forEach(System.out::println);

Validation

jsonfeed4j uses standard Bean Validation 1.1 (spec) annotations to enforce JSON Feed's required fields. However, no implementation is included, so validation can be performed with whichever implementation you prefer, such as Hibernate Validator. Custom validators are provided for cases in which there are several optional fields, but at least one must be present. Examples include item.content_text and item.content_text.

Optional fields are wrapped in an Optional to make it obvious.

Validator validator = getValidator();
JsonFeed jsonFeed = getJsonFeed();

Set<ConstraintViolations<?>> violations = validator.validate(jsonFeed);

Extensions

JSON Feed allows extensions at every level. All jsonfeed4j model classes have a Extensions getExtensions() method. From the Extensions object, you can retrieve the extension's root by its name without the underscore. For example:

{
  "_plugin1": {
    "key": "value"
  },
  "_plugin2": [ "a", "b", "c"],
  "_plugin3": "value2",
  "items": [
    {
      "id": "http://example.org/1",
      "content_text": "Some text",
      "_plugin4": 1234
    }
  ]
}
JsonFeed jsonFeed = getJsonFeed();
Extensions topLevelExtensions = jsonFeed.getExtensions();

Map<String, ?> plugin1 = topLevelExtensions.getMap("plugin1");
List<?> plugin2 = topLevelExtensions.getList("plugin2");
Object plugin3 = topLevelExtensions.get("value2");
Object plugin4 = jsonFeed.getItems().get(0).getExtensions().get("plugin4");

Versions

Version
0.1.0