tech.anima:jackson-datatype-tinytypes

Typed wrappers on native types - Jackson module.

License

License

MIT License
Categories

Categories

Data Jackson JSON
GroupId

GroupId

tech.anima
ArtifactId

ArtifactId

jackson-datatype-tinytypes
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

tech.anima:jackson-datatype-tinytypes
Typed wrappers on native types - Jackson module.
Project URL

Project URL

https://caligin.github.io/tinytypes/
Source Code Management

Source Code Management

https://github.com/caligin/tinytypes

Download jackson-datatype-tinytypes

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
tech.anima : tinytypes-meta jar 1.1.1
com.fasterxml.jackson.core : jackson-databind jar 2.11.0

test (2)

Group / Artifact Type Version
tech.anima : tinytypes-testing jar 1.1.1
junit : junit jar 4.13

Project Modules

There are no modules declared in this project.

TinyTypes

Build Status

What

Type safe wrappers on native types && support for commonly used frameworks.

See my slides 'bout it.

Status

Supported libraries/frameworks:

  • Jackson
  • Jersey

this implies:

  • Dropwizard (resources only, only JSON mediaType)

Defining a TinyType

Add tinytypes dep (Maven):

<dependency>
    <groupId>tech.anima</groupId>
    <artifactId>tinytypes</artifactId>
    <version>1.1.0</version>
</dependency>
  • Extend one of the base TinyTypes classes
  • It must not be abstract
  • Provide a constructor matching the one in the base class

Example:

public class SomeKindOfId extends StringTinyType {
    public SomeKindOfId(String value) {
        super(value);
        // ... additional validation or restrictions here
    }
}

Use with Jackson

Add jackson dep (Maven):

<dependency>
    <groupId>tech.anima</groupId>
    <artifactId>jackson-datatype-tinytypes</artifactId>
    <version>1.1.0</version>
</dependency>

Register module on ObjectMapper:

new ObjectMapper().registerModule(new TinyTypesModule())

Profit!

objectMapper.writeValueAsString(new SomeKindOfId("ag7weq")); // "ag7weq"

objectMapper.readValue("ag7weq", SomeKindOfId.class); // SomeKindOfId#ag7weq

Use with Jersey

Add jersey dep (Maven):

<dependency>
    <groupId>tech.anima</groupId>
    <artifactId>tinytypes-jersey</artifactId>
    <version>1.1.0</version>
</dependency>

Register module on ObjectMapper:

new ObjectMapper().registerModule(new TinyTypesModule())

Register the ParamProvider:

.addProvider(TinyTypesParamProvider.class)

Register the HeaderDelegates:

JerseyResponseSupport.registerTinyTypes(
        Samples.Str.class,
        ... (other TTs here)
);

Profit!

(See tinytypes-examples test cases for more on how to use them with Jersey)

Planned for the future

  • Android Parchelable
  • Hibernate
  • Spring
  • Xstream

I won't prioritize until I have a real necessity to use, PRs are welcome.

Versions

Version
1.1.1
1.1.0