JAX-RS Moshi

Message body reader/writer and parameter converter which uses Moshi.

License

License

Categories

Categories

Moshi Data JSON
GroupId

GroupId

com.jakewharton
ArtifactId

ArtifactId

jax-rs-moshi
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

JAX-RS Moshi
Message body reader/writer and parameter converter which uses Moshi.
Source Code Management

Source Code Management

http://github.com/JakeWharton/jax-rs-moshi

Download jax-rs-moshi

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
javax.ws.rs : javax.ws.rs-api jar 2.0.1
com.squareup.moshi : moshi jar 1.5.0

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
com.google.auto.value : auto-value jar 1.4.1

Project Modules

There are no modules declared in this project.

JAX-RS Moshi JSON Handlers

A message body reader/writer and parameter converter which uses Moshi to handle JSON.

Usage

ResourceConfig resourceConfig = new ResourceConfig();

Moshi moshi = new Moshi.Builder().build();

// Handles any request body marked as consuming application/json.
resourceConfig.register(new MoshiMessageBodyReader(moshi));
// Handles any response body marked as producing application/json.
resourceConfig.register(new MoshiMessageBodyWriter(moshi));
// Handles any parameter annotated with @Json.
resourceConfig.register(new MoshiParamConverterFactory(moshi));

(This example uses Jersey, but any JAX-RS-compatible implementation will work.)

The message body converters allow JSON serialization for request and response bodies:

@POST @Path("register") //
@Consumes(MediaType.APPLICATION_JSON) //
@Produces(MediaType.APPLICATION_JSON) //
public RegisterResponse register(RegisterRequest registerRequest) {
  // ...
}

The parameter converter allow JSON serialization for @Json-annotated parameters.

@POST @Path("checkin") //
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) //
@Produces(MediaType.APPLICATION_JSON) //
public CheckinResponse checkin( //
    @FormParam("user") @Json User user) {
  // ...
}

Download

Gradle:

compile 'com.jakewharton:jax-rs-moshi:1.0.0'

or Maven:

<dependency>
  <groupId>com.jakewharton</groupId>
  <artifactId>jax-rs-moshi</artifactId>
  <version>1.0.0</version>
</dependency>

Snapshot versions are available in the Sonatype 'snapshots' repository: https://oss.sonatype.org/content/repositories/snapshots/

License

Copyright 2017 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.0