groovy-beans-with-jackson

Implementations of the Jackson API to better support Groovy Beans without annotations, including groovy.transform.Immutable beans.

Лицензия

Лицензия

Категории

Категории

Groovy Языки программирования Immutables Библиотеки уровня приложения Code Generators Jackson Данные JSON
Группа

Группа

com.phasebash.jackson
Идентификатор

Идентификатор

groovy-beans-with-jackson-immutables-module
Последняя версия

Последняя версия

1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

groovy-beans-with-jackson
Implementations of the Jackson API to better support Groovy Beans without annotations, including groovy.transform.Immutable beans.
Ссылка на сайт

Ссылка на сайт

https://github.com/phasebash/groovy-beans-with-jackson
Организация-разработчик

Организация-разработчик

Brandon Zeeb
Система контроля версий

Система контроля версий

https://github.com/phasebash/groovy-beans-with-jackson

Скачать groovy-beans-with-jackson-immutables-module

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.phasebash.jackson/groovy-beans-with-jackson-immutables-module/ -->
<dependency>
    <groupId>com.phasebash.jackson</groupId>
    <artifactId>groovy-beans-with-jackson-immutables-module</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.phasebash.jackson/groovy-beans-with-jackson-immutables-module/
implementation 'com.phasebash.jackson:groovy-beans-with-jackson-immutables-module:1.0'
// https://jarcasting.com/artifacts/com.phasebash.jackson/groovy-beans-with-jackson-immutables-module/
implementation ("com.phasebash.jackson:groovy-beans-with-jackson-immutables-module:1.0")
'com.phasebash.jackson:groovy-beans-with-jackson-immutables-module:jar:1.0'
<dependency org="com.phasebash.jackson" name="groovy-beans-with-jackson-immutables-module" rev="1.0">
  <artifact name="groovy-beans-with-jackson-immutables-module" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.phasebash.jackson', module='groovy-beans-with-jackson-immutables-module', version='1.0')
)
libraryDependencies += "com.phasebash.jackson" % "groovy-beans-with-jackson-immutables-module" % "1.0"
[com.phasebash.jackson/groovy-beans-with-jackson-immutables-module "1.0"]

Зависимости

compile (4)

Идентификатор библиотеки Тип Версия
org.codehaus.groovy : groovy-all jar 2.2.1
com.fasterxml.jackson.core : jackson-core jar 2.3.1
org.slf4j : slf4j-api jar 1.7.5
com.fasterxml.jackson.core : jackson-databind jar 2.3.1

test (7)

Идентификатор библиотеки Тип Версия
ch.qos.logback : logback-classic jar 1.0.13
org.slf4j : jcl-over-slf4j jar 1.7.5
org.hamcrest : hamcrest-library jar 1.3
org.slf4j : log4j-over-slf4j jar 1.7.5
junit : junit jar 4.11
org.hamcrest : hamcrest-core jar 1.3
org.gmock : gmock jar 0.8.3

Модули Проекта

Данный проект не имеет модулей.

groovy-beans-with-jackson

Implementations of the Jackson API to support Groovy Beans, particularly @Immutables

Current Status

[Build Status] (https://travis-ci.org/phasebash/groovy-beans-with-jackson)

Use Cases

Groovy Beans are a particularly attractive way of developing Java Beans. Yet when making the most of what Groovy provides, particularly the @Immutable transform, this presents challenges during deserialization as Jackson will not be able to find a default constructor (or any annotations if your classes are fully Groovy).

Consider the following Groovy Bean.

@Immutable
class BeanBag {
    Integer count
    String texture
    Zipper zipper
}

Without modification, this stacktrace might look familiar:

com.fasterxml.jackson.databind.JsonMappingException:
No suitable constructor found for type
[simple type, class BeanBag]:
can not instantiate from JSON object (need to add/enable type information?)

As a first naive step, one could provide a private constructor:

@Immutable
class BeanBag {
    private BeanBag() {}
    Integer count
    String texture
    Zipper zipper
}

And would could expect to receive this message:

Groovyc: Explicit constructors not allowed for @Immutable class: BeanBag

Yet, the @Immutable transform prohibits this, any other constructors are also forbidden.

In Use

In order to deserialize @Immutable GroovyBeans without fuss, simply provide the ObjectMapper with a Jackson Module which provides the necessary ValueInstantiator to allow Jackson to instantiate GroovyBeans by their generated HashMap constructors.

ObjectMapper objectMapper = new ObjectMapper()
objectMapper.registerModule(new GroovyImmutableModule())

// this is now possible.
BeanBag beanBag = objectMapper.readValue('{"count": 100, "texture": "smooth"}', BeanBag)

Coordinates

You may make use of this module with the following coordinates:

Maven

<dependency>
    <groupId>com.phasebash.jackson</groupId>
    <artifactId>groovy-beans-with-jackson-immutables-module</artifactId>
    <version>1.0</version>
</dependency>

Gradle

compile(
    [groupId: 'com.phasebash.jackson', name: 'groovy-beans-with-jackson-immutables-module', version: '1.0']
)

Questions, Feedback?

Feel free to submit an issue ticket through github or contact me directly. I will help you.

License

The groovy-beans-with-jackson has been released under Apache 2.0 as per all it's dependencies.

Версии библиотеки

Версия
1.0