Jackson Module Http Query

A jackson module for allowing HTTP queries to be represented as typed objects

License

License

Categories

Categories

Jackson Data JSON
GroupId

GroupId

com.github.trickl
ArtifactId

ArtifactId

jackson.module.httpquery
Last Version

Last Version

1.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

Jackson Module Http Query
A jackson module for allowing HTTP queries to be represented as typed objects
Project URL

Project URL

http://github.com/trickl/jackson-module-http-query/
Source Code Management

Source Code Management

https://github.com/trickl/jackson-module-http-query

Download jackson.module.httpquery

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-core jar
com.fasterxml.jackson.core : jackson-databind jar
com.fasterxml.jackson.module : jackson-module-parameter-names jar

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.10

test (5)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.4.0
org.junit.jupiter : junit-jupiter-engine jar 5.4.0
org.junit.jupiter : junit-jupiter-params jar 5.3.2
com.fasterxml.jackson.datatype : jackson-datatype-jsr310 jar
com.fasterxml.jackson.datatype : jackson-datatype-jdk8 jar

Project Modules

There are no modules declared in this project.

Jackson Module HTTP Query

Maven Central build_status Maintainability Test Coverage License

A jackson module for allowing HTTP queries to be represented as typed objects

Installation

To install from Maven Central:

<dependency>
  <groupId>com.github.trickl</groupId>
  <artifactId>jackson-module-httpquery</artifactId>
  <version>1.0.2</version>
</dependency>

Registering module

Like all standard Jackson modules (libraries that implement Module interface), registration is done as follows:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new HttpQueryModule());

after which functionality is available for all normal Jackson operations.

Purpose

Converts POJOs to query strings and vice versa.

  • Use type objects for convenient conversion to query strings (and back).
  • Less boilerplate code required for supporting a variety of query combinations.
  • Supports existing Jackson JSON annotations for formatting.
  • Extra annotations allow for different strategies on handling multi-valued parameters.

Usage Example

@HttpQuery
private static class TypedExample {
    private String valueA;

    private String valueB;

    private int valueC;
}

// To produce "?valueA=test&valueB=testB&valueC=123"...
TypedQuery typed = new TypedQuery(... // omitted for brevity
String queryString = objectMapper.valueToTree(typedQuery).textValue();

Features

  • Supports many Jackson annotations
    • @JsonProperty (have a different query parameter name from the variable name).
    • @JsonIgnore (don't serialize a property)
    • @JsonFormat (useful for date strings).
  • Supports new parameters
    • @HttpQuery (required to serialize to a query string, not a JSON object).
    • @HttpQueryDelimited (serialize a multi valued property using a delimited list e.g "?values=1,2,3").
    • @HttpQueryNoValue (allow boolean valueless params, e.g. "?debug")