Skip to content

Provides a Jersey MessageBodyReader that converts multipart/form-data requests to POJOs using Jackson.

License

Notifications You must be signed in to change notification settings

VEuPathDB/lib-jersey-multipart-jackson-pojo

Repository files navigation

Jersey Multipart for Jackson POJOs

Jersey message body reader and event listener for parsing multipart/form-data requests into Jackson annotated POJOs.

Usage

register(MultipartMessageBodyReader.class);
register(MultipartApplicationEventListener.class);

Example

Controller Method
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void myController(SomePOJO pojo) {
  ...
}
Input POJO
public class SomePOJO {
  @JsonSetter("foo")
  public void setFoo(String foo) { ... }

  @JsonSetter("bar")
  public void setBar(File bar) { ... }
}

Development

Testing

A test server using this library can be spun up using the command:

./gradlew run

Once this server is online, you may make multipart POST requests to the service at localhost:8080 using the following endpoints:

/model

Logs the properties on the model class parsed from the input request.

This method expects the form params foo, bar, and fizz as per the model class that the quest will be parsed into.

Model Class Fields
Field Allowed Values Description

foo

Any String

A string parameter.

bar

Any file or value

A file parameter.

fizz

"some value"

An enum parameter

/enum

Logs the enum value parsed from the input request.

This method expects at least 1 form parameter with any field name that will be parsed into a value on the test enum class.

See the test enum class definition for permissible values.

About

Provides a Jersey MessageBodyReader that converts multipart/form-data requests to POJOs using Jackson.

Resources

License

Stars

Watchers

Forks

Packages